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"]) }