Skip to content

Commit

Permalink
PM-9999: added option to ignore route attribute in the route_table ob… (
Browse files Browse the repository at this point in the history
#4)

* PM-9999: added option to ignore route attribute in the route_table object
  • Loading branch information
MichaelYefet1 authored Oct 28, 2024
1 parent 9b6128e commit 3f0eaa2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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), [])
Expand Down
2 changes: 1 addition & 1 deletion vpc/subnet_group/output.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
17 changes: 16 additions & 1 deletion vpc/subnet_group/route_table.tf
Original file line number Diff line number Diff line change
@@ -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"])
}

0 comments on commit 3f0eaa2

Please sign in to comment.