-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
error associating EC2 Transit Gateway Route Table : Resource.AlreadyAssociated #16452
Comments
OK, I have a workaround for this issue, it's ugly but it works.
resource "null_resource" "disassociateRt" {
depends_on = [aws_ec2_transit_gateway_vpc_attachment.tgw-attachment]
provisioner "local-exec" {
command="aws ec2 disassociate-transit-gateway-route-table --transit-gateway-route-table-id ${data.aws_ec2_transit_gateway.selected.association_default_route_table_id} --transit-gateway-attachment-id ${aws_ec2_transit_gateway_vpc_attachment.tgw-attachment.id} --profile RoutingAccount;sleep 90"
}
}
resource "aws_ec2_transit_gateway_route_table_association" "spokeAccountRouteTableAssociation" {
depends_on = [null_resource.disassociateRt]
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.tgw-attachment.id
transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.SpokeAccountAttachmentRoutTable.id
provider = aws.routing
} My AWS credentials are stored in ~/.aws/credentials using profiles. Permanent Fix |
Another option, if you can modify the transit gateway is to set default_route_table_association to disable as below. If you do that then you don't have to make any additional changes. resource "aws_ec2_transit_gateway" "routing_transit_gateway" {
description = "TransactRx Shared TGW"
tags = {
Name = "TransactRxSharedTGW"
}
auto_accept_shared_attachments = "enable"
default_route_table_association = "disable"
} |
Facing the same issue in a similar setup.
The problem with this approach is that you can't disable default association on the attachment side:
If you set default_route_table_association to false in such a setup, creation of the corresponding ec2_transit_gateway_vpc_attachment_accepter resource will fail (it will look for the default route table). So yeah, having this in place would help solve the issue I believe:
|
+1 for that |
This functionality has been released in v5.2.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Community Note
Terraform CLI and Terraform AWS Provider Version
Terraform v0.13.5
Affected Resource(s)
Terraform Configuration Files
Debug Output
If you need this please let me know as I can see sensitive data in the TRACE log file.
Expected Behaviour
We share the TGW from one account (network) to a spoke account. We need to make the TGW VPC attachment to the TGW and then modify the route table association.
What I expect with the code above it that the Transit Gateway Attachment is removed from the Default TGW route table and attached to the desired TGW Route Table
Actual Behaviour
Steps to Reproduce
terraform apply
Important Factoids
TGW is shared via RAM from network account to spoke account. Spoke account Code has a second AWS provider within the configuration that allows it to assume a role in the network account to update the Route Table association
References
The text was updated successfully, but these errors were encountered: