Skip to content

[Bug]: aws_ec2_transit_gateway_peering_attachment options block causes 400 error #41360

@madchap

Description

@madchap

Terraform Core Version

OpenTofu 1.8.8

AWS Provider Version

5.86.1

Affected Resource(s)

  • aws_ec2_transit_gateway_peering_attachment

I am specifying right away that I am using eu-central-2 (main below, opt-in), and I've had my share of issues with it. The 2nd region (DR) is eu-central-1.

The first time the plan got applied, dynamic_routing was disabled. So I applied the option to enable it. This forces a replacement. Deletion went through, and was greeted with the following upon the re-creation attempt:

Error: creating EC2 Transit Gateway Peering Attachment: operation error EC2: CreateTransitGatewayPeeringAttachment, https response error StatusCode: 400, RequestID: eb6353cf-41d2-496f-a82d-b7d0b725333c, api error IncorrectState: You cannot create a dynamic peering attachment.
  │
  │   with module.transit-gateways-cross-region-peering[0].aws_ec2_transit_gateway_peering_attachment.main_region,
  │   on x-region-transit-peering/x-tgw-attachements.tf line 1, in resource "aws_ec2_transit_gateway_peering_attachment" "main_region":
  │    1: resource "aws_ec2_transit_gateway_peering_attachment" "main_region" {

I have the following code, which worked the first time around:

resource "aws_ec2_transit_gateway_peering_attachment" "main_region" {
    # euc2 initiates the peering request

    peer_account_id         = data.aws_ec2_transit_gateway.dr_region.owner_id
    peer_region             = data.aws_region.dr_region.name
    peer_transit_gateway_id = data.aws_ec2_transit_gateway.dr_region.id
    transit_gateway_id      = data.aws_ec2_transit_gateway.main_region.id
    options {
        dynamic_routing = "enable"
    }

    tags = { 
        Name = "EUC1 <-> EUC2 Peering",
        Side = "Requestor" 
    }
}

resource "aws_ec2_transit_gateway_peering_attachment_accepter" "dr_region" {
    # dr accepts the pending request
    provider = aws.dr

    transit_gateway_attachment_id = aws_ec2_transit_gateway_peering_attachment.main_region.id

    tags = { Side = "Acceptor" }
}

data "aws_ec2_transit_gateway" "main_region" {
  filter {
    name   = "options.amazon-side-asn"
    values = ["64532"]
  }
}

data "aws_ec2_transit_gateway" "dr_region" {
    provider = aws.dr
  
    filter {
        name   = "options.amazon-side-asn"
        values = ["64533"]
    }
}

data "aws_ec2_transit_gateway_peering_attachment" "dr_region" {
    provider = aws.dr

    filter {
        name   = "transit-gateway-id"
        values = [ data.aws_ec2_transit_gateway.dr_region.id ]
    }

    depends_on = [ aws_ec2_transit_gateway_peering_attachment.main_region ]
}

data "aws_region" "main" {}

data "aws_region" "dr_region" {
    provider = aws.dr
}

Expected Behavior

The re-creation would go through, as the resources are in "Deleted" state, they can be re-created.
Passing the options block works as expected to enable or disable dynamic routing.

Actual Behavior

I can no longer create TGW peering between the regions if specifying the options block.

Terraform Configuration Files

All above normally.

I isolated the run to just this module, which is all the configuration pasted above. Given nothing else has changed, I can only assume the "Deleted"

Steps to Reproduce

  • Pick the eu-central-2 (main) and eu-central-1 (dr) regions and no other. (just had some undocumented behavior with AWS managed Grafana because of euc2 confirmed by AWS, so...).
  • Create TGWs
  • Change the dynamic option
  • Re-apply the plan. It should force a replacement.
  • Observe you can't recreate

Debug Output

gpg encrypted debug log.

tf_run_gpg.log

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/transitgatewayIssues and PRs that pertain to the transitgateway service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions