From 3f0eaa242d742569652be47b6100bc21def480b7 Mon Sep 17 00:00:00 2001 From: MichaelYefet1 <101189972+MichaelYefet1@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:07:24 +0200 Subject: [PATCH] =?UTF-8?q?PM-9999:=20added=20option=20to=20ignore=20route?= =?UTF-8?q?=20attribute=20in=20the=20route=5Ftable=20ob=E2=80=A6=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PM-9999: added option to ignore route attribute in the route_table object --- variables.tf | 1 + vpc/subnet_group/output.tf | 2 +- vpc/subnet_group/route_table.tf | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index 746a345..5d99b0a 100644 --- a/variables.tf +++ b/variables.tf @@ -10,6 +10,7 @@ variable "vpc_group" { type = object({ offset = number assign_public_ips = bool extra_subnet_tags = optional(map(string), {}) + ignore_routes_changes = optional(bool, false) })) public_igw_subnet_groups = list(string) nacl_subnet_groups = optional(list(string), []) diff --git a/vpc/subnet_group/output.tf b/vpc/subnet_group/output.tf index fa82d93..071cc22 100644 --- a/vpc/subnet_group/output.tf +++ b/vpc/subnet_group/output.tf @@ -1,6 +1,6 @@ output "subnet_group" { value = { subnet_ids = aws_subnet.subnet.*.id - route_table_id = aws_route_table.route_table.id + route_table_id = var.subnet_group_properties["ignore_routes_changes"] ? aws_route_table.route_table_ignore_routes[0].id : aws_route_table.route_table[0].id } } diff --git a/vpc/subnet_group/route_table.tf b/vpc/subnet_group/route_table.tf index b96c721..1fa82ef 100644 --- a/vpc/subnet_group/route_table.tf +++ b/vpc/subnet_group/route_table.tf @@ -1,11 +1,26 @@ resource "aws_route_table" "route_table" { vpc_id = var.vpc_id tags = tomap({"Name" = "${var.subnet_group_properties["subnet_group_name"]}-route_table.${var.vpc_name}"}) + + count = var.subnet_group_properties["ignore_routes_changes"] ? 0 : 1 +} + +resource "aws_route_table" "route_table_ignore_routes" { + vpc_id = var.vpc_id + tags = tomap({"Name" = "${var.subnet_group_properties["subnet_group_name"]}-route_table.${var.vpc_name}"}) + + lifecycle { + ignore_changes = [ + route + ] + } + + count = var.subnet_group_properties["ignore_routes_changes"] ? 1 : 0 } resource "aws_route_table_association" "route_table_assoc" { subnet_id = element(aws_subnet.subnet.*.id, count.index) - route_table_id = element(aws_route_table.route_table.*.id, count.index) + route_table_id = var.subnet_group_properties["ignore_routes_changes"] ? aws_route_table.route_table_ignore_routes[0].id : aws_route_table.route_table[0].id count = length(var.subnet_group_properties["availability_zones"]) }