diff --git a/vpc-transit-gateway-association/README.md b/vpc-transit-gateway-association/README.md index 826807f..b244ecf 100644 --- a/vpc-transit-gateway-association/README.md +++ b/vpc-transit-gateway-association/README.md @@ -34,20 +34,21 @@ module "vpc_tgw" { | Name | Source | Version | |------|--------|---------| -| [routing\_attachment](#module\_routing\_attachment) | git@github.e.it.census.gov:terraform-modules/aws-vpc-setup.git//routing | tf-upgrade | +| [routing\_attachment\_ipv4](#module\_routing\_attachment\_ipv4) | git@github.e.it.census.gov:terraform-modules/aws-vpc-setup.git//routing | tf-upgrade | ## Resources | Name | Type | |------|------| -| [aws_route.gateway](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource | +| [aws_route.gateway_ipv4](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource | | [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source | | [aws_arn.network_account](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source | | [aws_availability_zone.zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zone) | data source | | [aws_availability_zones.zones](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source | | [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | [aws_caller_identity.network_account](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | -| [aws_ec2_managed_prefix_list.tgw](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source | +| [aws_ec2_managed_prefix_list.tgw_ipv4](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_list) | data source | +| [aws_ec2_managed_prefix_lists.tgw_ipv4](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_managed_prefix_lists) | data source | | [aws_ec2_transit_gateway.gateway_peer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway) | data source | | [aws_ec2_transit_gateway.gateway_self](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway) | data source | | [aws_ec2_transit_gateway_route_table.route_tables_peer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ec2_transit_gateway_route_table) | data source | @@ -68,7 +69,7 @@ module "vpc_tgw" { | [network\_account\_profile](#input\_network\_account\_profile) | AWS profile of the source account sharing the VPC resources | `string` | n/a | yes | | [override\_prefixes](#input\_override\_prefixes) | Override built-in prefixes by component. This should be used primarily for common infrastructure things | `map(string)` | `{}` | no | | [private\_subnets\_ids](#input\_private\_subnets\_ids) | List of private subnet objects including: subnet, label, availability\_zone, id |
list(object({
subnet = string
label = string
availability_zone = string
id = string
})) | `[]` | no |
-| [route\_prefix\_list\_name](#input\_route\_prefix\_list\_name) | Shared prefix list name used for routing to TGW. It is comprised of all of the network CIDR blocks in AWS using TGW. | `string` | `"transit-gateway.prod.ipv4"` | no |
+| [route\_prefix\_list\_name](#input\_route\_prefix\_list\_name) | Shared prefix list name used for routing to TGW. It is comprised of all of the network CIDR blocks in AWS using TGW. | `string` | `"transit-gateway.prod"` | no |
| [route\_table\_label](#input\_route\_table\_label) | Route table lable for the attachment subnets | `string` | `"attachment"` | no |
| [tags](#input\_tags) | AWS Tags to apply to appropriate resources (S3, KMS). Do not include safeguard tags here, use the data\_safeguard field for such things. | `map(string)` | `{}` | no |
| [transit\_gateway\_environment](#input\_transit\_gateway\_environment) | Transit Gateway Environment (aka, VRF) to which to connnect this VPC | `string` | n/a | yes |
diff --git a/vpc-transit-gateway-association/routing.tf b/vpc-transit-gateway-association/routing.tf
index 9f8f8d7..88c21b5 100644
--- a/vpc-transit-gateway-association/routing.tf
+++ b/vpc-transit-gateway-association/routing.tf
@@ -1,4 +1,4 @@
-module "routing_attachment" {
+module "routing_attachment_ipv4" {
source = "git@github.e.it.census.gov:terraform-modules/aws-vpc-setup.git//routing?ref=tf-upgrade"
vpc_id = var.vpc_id
@@ -23,19 +23,24 @@ module "routing_attachment" {
)
}
-data "aws_ec2_managed_prefix_list" "tgw" {
+data "aws_ec2_managed_prefix_lists" "tgw_ipv4" {
filter {
name = "prefix-list-name"
- values = [var.route_prefix_list_name]
+ values = [var.route_prefix_list_name, format("%v.ipv4", var.route_prefix_list_name)]
}
}
-resource "aws_route" "gateway" {
- for_each = module.routing.private_route_table_ids
+data "aws_ec2_managed_prefix_list" "tgw_ipv4" {
+ for_each = data.aws_ec2_managed_prefix_lists.tgw_ipv4.ids
+ id = each.key
+}
+
+resource "aws_route" "gateway_ipv4" {
+ for_each = module.routing_ipv4.private_route_table_ids
route_table_id = each.value
# destination_cidr_block = "10.128.0.0/16"
- destination_prefix_list_id = data.aws_ec2_managed_prefix_list.tgw.id
+ destination_prefix_list_id = one([for k, v in data.aws_ec2_managed_prefix_list.tgw_ipv4 : k if v.address_family == "IPv4"])
transit_gateway_id = data.aws_ec2_transit_gateway.gateway_east.id
depends_on = [aws_ec2_transit_gateway_vpc_attachment.vpc_attachment]
diff --git a/vpc-transit-gateway-association/variables.tf b/vpc-transit-gateway-association/variables.tf
index f09d671..a67a7e1 100644
--- a/vpc-transit-gateway-association/variables.tf
+++ b/vpc-transit-gateway-association/variables.tf
@@ -27,5 +27,5 @@ variable "route_table_label" {
variable "route_prefix_list_name" {
description = "Shared prefix list name used for routing to TGW. It is comprised of all of the network CIDR blocks in AWS using TGW."
type = string
- default = "transit-gateway.prod.ipv4"
+ default = "transit-gateway.prod"
}