Im working with the AWS service Cloud-WAN and im running into issues when attaching a peered transit gateway with a policy route table via terraform using the resource aws_ec2_transit_gateway_policy_table_association . I keep getting an error saying "Error: reading EC2 Transit Gateway Attachment (tgw-attach-00c6bc16f58d5c895): couldn't find resource" but if i do it manually it works.
Im using terraform workspaces and I created a workspace called dev, then I created a tfvars file that contains all my variables. Below is my file structure.
├── README.md
├── docs
│ └── terraform.md
├── environments
│ ├── dev
│ │ └── dev.tfvars
│ └── prod
│ └── prod.tfvars
└── terraform
├── data.tf
├── main.tf
├── provider.tf
└── variables.tf
When i created the resource aws_networkmanager_transit_gateway_peering it peers the transit gateway with the cloud-wan core network but by default it does not attach a policy route table. There is another resource to attach this peering connection to an existing policy route table. The resource is aws_ec2_transit_gateway_policy_table_association but that keeps giving me the error stated above. Below is my code example.
resource "aws_networkmanager_transit_gateway_peering" "tgw_peering" {
count = length(var.transit_gateway_list)
core_network_id = awscc_networkmanager_core_network.core_network.id
transit_gateway_arn = var.transit_gateway_list[count.index]
}
resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association" {
count = length(var.transit_gateway_list)
transit_gateway_attachment_id = aws_networkmanager_transit_gateway_peering.tgw_peering[count.index].transit_gateway_peering_attachment_id
transit_gateway_policy_table_id = var.transit_gateway_policy_table_id[count.index]
}
When I do the terraform plan I get the below output.
Terraform will perform the following actions:
# aws_ec2_transit_gateway_policy_table_association.tgw_association[0] will be created
+ resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association" {
+ id = (known after apply)
+ resource_id = (known after apply)
+ resource_type = (known after apply)
+ transit_gateway_attachment_id = "tgw-attach-00c6bc16f58d5c895"
+ transit_gateway_policy_table_id = "tgw-ptb-07cc67e9f611063a2"
}
# aws_ec2_transit_gateway_policy_table_association.tgw_association[1] will be created
+ resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association" {
+ id = (known after apply)
+ resource_id = (known after apply)
+ resource_type = (known after apply)
+ transit_gateway_attachment_id = "tgw-attach-01bbffa4b63917c4a"
+ transit_gateway_policy_table_id = "tgw-ptb-0d8e028a9ee7d7b58"
}
But then shortly after I get the following error.
aws_ec2_transit_gateway_policy_table_association.tgw_association[0]: Creating...
aws_ec2_transit_gateway_policy_table_association.tgw_association[1]: Creating...
awscc_networkmanager_core_network.core_network: Modifying... [id=core-network-09b868cce2cf4b66f]
awscc_networkmanager_core_network.core_network: Modifications complete after 8s [id=core-network-09b868cce2cf4b66f]
╷
│ Error: reading EC2 Transit Gateway Attachment (tgw-attach-00c6bc16f58d5c895): couldn't find resource
│
│ with aws_ec2_transit_gateway_policy_table_association.tgw_association[0],
│ on main.tf line 40, in resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association":
│ 40: resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association" {
│
╵
╷
│ Error: reading EC2 Transit Gateway Attachment (tgw-attach-01bbffa4b63917c4a): couldn't find resource
│
│ with aws_ec2_transit_gateway_policy_table_association.tgw_association[1],
│ on main.tf line 40, in resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association":
│ 40: resource "aws_ec2_transit_gateway_policy_table_association" "tgw_association" {
│
╵
Releasing state lock. This may take a few moments...
Thanks ahead of time to anyone that responds :)