-
-
Notifications
You must be signed in to change notification settings - Fork 242
feat: Allow specifying additional TGW routes in attached VPCs #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,18 @@ locals { | |
| } | ||
| ] | ||
| ]) | ||
|
|
||
| vpc_route_table_additional_cidrs = flatten([ | ||
| for k, v in var.vpc_attachments : [ | ||
| for rtb_id in try(v.vpc_route_table_ids, []) : [ | ||
| for cidr in try(v.tgw_additional_cidrs, []) : { | ||
| rtb_id = rtb_id | ||
| cidr = cidr | ||
| tgw_id = var.create_tgw ? aws_ec2_transit_gateway.this[0].id : v.tgw_id | ||
| } | ||
| ] | ||
| ] | ||
| ]) | ||
| } | ||
|
|
||
| ################################################################################ | ||
|
|
@@ -127,7 +139,7 @@ resource "aws_ec2_transit_gateway_route" "this" { | |
| transit_gateway_attachment_id = tobool(try(local.vpc_attachments_with_routes[count.index][1].blackhole, false)) == false ? aws_ec2_transit_gateway_vpc_attachment.this[local.vpc_attachments_with_routes[count.index][0].key].id : null | ||
| } | ||
|
|
||
| resource "aws_route" "this" { | ||
| resource "aws_route" "destination_cidr" { | ||
| for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => { | ||
| cidr = x.cidr, | ||
| tgw_id = x.tgw_id | ||
|
|
@@ -143,6 +155,24 @@ resource "aws_route" "this" { | |
| depends_on = [aws_ec2_transit_gateway_vpc_attachment.this] | ||
| } | ||
|
|
||
| moved { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with the change above this becomes unneeded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As stated above, your suggestion will cause an outage for all users of this module. I really don't think this is the right approach here. |
||
| from = aws_route.this | ||
| to = aws_route.destination_cidr | ||
| } | ||
|
|
||
| resource "aws_route" "additional_cidrs" { | ||
| for_each = { for x in local.vpc_route_table_additional_cidrs : "${x.rtb_id}_${x.cidr}" => { | ||
| cidr = x.cidr | ||
| rtb_id = x.rtb_id | ||
| tgw_id = x.tgw_id | ||
| } } | ||
|
|
||
| route_table_id = each.value["rtb_id"] | ||
| destination_cidr_block = try(each.value.ipv6_support, false) ? null : each.value["cidr"] | ||
| destination_ipv6_cidr_block = try(each.value.ipv6_support, false) ? each.value["cidr"] : null | ||
| transit_gateway_id = each.value["tgw_id"] | ||
| } | ||
|
|
||
| resource "aws_ec2_transit_gateway_route_table_association" "this" { | ||
| for_each = { | ||
| for k, v in var.vpc_attachments : k => v if var.create_tgw && var.create_tgw_routes && try(v.transit_gateway_default_route_table_association, true) != true | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to introduce additional resources
resource "aws_route" "additional_cidrs"andresource "aws_route" "destination_cidr"Let's simplify the code a bit by looping over the merged map of
local.vpc_route_table_destination_cidrandlocal.vpc_route_table_additional_cidrslike the following:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyarmoshyk this change isn't possible without causing the deletion of all existing
aws_route.thisresources, as you can't do dynamicmovedblocks.Given that the key for the default route will depend on the current cidr block, there is no way to write a
movedblock that will move the existing route entry into a key for the currentaws_route.thisresource.As I stated in the PR description, this leaves us only two options:
aws_route.thisresource as is, but add theaws_route.additional_cidrsresource which has a map with key. This violates terraform style, but if we want to drop themovedblock I would be okay with that if the module owners are okay with ignoring terraform style.additional_cidrsobject which is a map.If we just do what you suggest, I would have to remove the
movedblock which would mean that when users upgrade the terraform module the route entry will be deleted and re-created which could cause traffic disruption. This is highly undesirable in my opinion