diff --git a/vpc-transit-gateway-association/README.md b/vpc-transit-gateway-association/README.md index a1e7df1..7de29de 100644 --- a/vpc-transit-gateway-association/README.md +++ b/vpc-transit-gateway-association/README.md @@ -31,6 +31,7 @@ This sets up the necessary transit gateway configuration for attaching a VPC wit | [aws.network\_account](#provider\_aws.network\_account) | >= 3.66.0 | | [aws.peer](#provider\_aws.peer) | >= 3.66.0 | | [aws.self](#provider\_aws.self) | >= 3.66.0 | +| [null](#provider\_null) | >= 3.0 | ## Modules @@ -50,6 +51,7 @@ This sets up the necessary transit gateway configuration for attaching a VPC wit | [aws_ec2_transit_gateway_route_table_propagation.vpc_self_own_rt](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_route_table_propagation) | resource | | [aws_ec2_transit_gateway_vpc_attachment.vpc_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_transit_gateway_vpc_attachment) | resource | | [aws_route.gateway_ipv4](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource | +| [null_resource.vpc_attachment_exists](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | 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 | diff --git a/vpc-transit-gateway-association/routing.tf b/vpc-transit-gateway-association/routing.tf index 8663443..31d8c11 100644 --- a/vpc-transit-gateway-association/routing.tf +++ b/vpc-transit-gateway-association/routing.tf @@ -37,6 +37,13 @@ data "aws_ec2_managed_prefix_list" "tgw_ipv4" { id = each.key } +resource "null_resource" "vpc_attachment_exists" { + triggers = { + vpc_attachment = one(aws_ec2_transit_gateway_vpc_attachment.vpc_attachment[*].id) + } +} + + # pick the first prefix list found, either NAME or NAME.ipv4 resource "aws_route" "gateway_ipv4" { for_each = var.transit_gateway_routing_type == "self" ? module.routing_attachment_ipv4[0].private_route_table_ids : {} @@ -46,5 +53,5 @@ resource "aws_route" "gateway_ipv4" { 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_self.id - depends_on = [aws_ec2_transit_gateway_vpc_attachment.vpc_attachment] + depends_on = [null_resource.vpc_attachment_exists] }