hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.18k forks source link

[Bug]: aws_ec2_transit_gateway_route recreate when more then 1000 routes are present #33762

Closed deutmeyerbrianpfg closed 1 year ago

deutmeyerbrianpfg commented 1 year ago

Terraform Core Version

1.5.0

AWS Provider Version

5.5.0, 5.19.0

Affected Resource(s)

aws_ec2_transit_gateway_route

Expected Behavior

When running a plan for apply, the route should be found and no change should occur.

Actual Behavior

Routes are being returned in numerical order and anthing after route #1000 won't be returned. Terraform will say the route no longer exists and will try to recreate it. The results in a error because the route does actually exist. Any route that falls under the first 1,000 results works just fine.

Relevant Error/Panic Output Snippet

Terraform will perform the following actions:

  # aws_ec2_transit_gateway_route.rw_prod will be created
  + resource "aws_ec2_transit_gateway_route" "this" {
      + blackhole                      = false
      + destination_cidr_block         = "172.16.20.0/23"
      + id                             = (known after apply)
      + transit_gateway_attachment_id  = "tgw-attach-69280a1420191xxxx"
      + transit_gateway_route_table_id = "tgw-rtb-420929cc306c0xxxx"
    }

aws_ec2_transit_gateway_route.this: Creating...
╷
│ Error: creating EC2 Transit Gateway Route (tgw-rtb-420929cc306c0xxxx_172.16.20.0/23): RouteAlreadyExists: Route 172.16.20.0/23 already exists in Transit Gateway Route Table tgw-rtb-420929cc306c0xxxx.
│   status code: 400, request id: e6c7b37c-4a1a-43a4-9724-211c81b71787
│ 
│   with aws_ec2_transit_gateway_route.this,
│   on main.tf line 53, in resource "aws_ec2_transit_gateway_route" "this":
│   53: resource "aws_ec2_transit_gateway_route" "this" {
│ 
╵

Terraform Configuration Files

resource "aws_ec2_transit_gateway_route" "this" { destination_cidr_block = "172.16.20.0/23 transit_gateway_attachment_id = "tgw-attach-69280a1420191xxxx" transit_gateway_route_table_id = "tgw-rtb-420929cc306c0xxxx" }

Steps to Reproduce

Make sure there are 1000 routes from the 10.0.0.0/8 network to ensure the 172.16.0.0/12 space gets returned last.

Debug Output

2023-10-04T18:48:05.481Z [WARN] provider.terraform-provider-aws_v5.5.0_x5: [WARN] EC2 Transit Gateway Route tgw-rtb-420929cc306c0xxxx_172.16.20.0/23 not found, removing from state 2023-10-04T18:48:05.482Z [WARN] Provider "registry.terraform.io/hashicorp/aws" produced an unexpected new value for aws_ec2_transit_gateway_route.this during refresh.

Panic Output

No response

Important Factoids

No response

References

I think this is the lookup on refresh: https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/ec2/transitgateway_route.go#L105

It only passing in the destination and the TGW route table ID. The API is only returning 1,000 repsonses. This should be updated so it can also be passed the attachment ID (if applicable) and blackhole status. Then the lookup can determine which additional filter to apply. https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/ec2/find.go#L4600

input := &ec2.SearchTransitGatewayRoutesInput{
        Filters: BuildAttributeFilterList(map[string]string{
            "type": ec2.TransitGatewayRouteTypeStatic,
        }),
        TransitGatewayRouteTableId: aws.String(transitGatewayRouteTableID),
    }

Max Results listed here: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_SearchTransitGatewayRoutes.html

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 1 year ago

This functionality has been released in v5.20.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!

github-actions[bot] commented 1 year ago

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. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.