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]: When creating GatewayLoadBalancer VPC Endpoints, AWS Provider does not wait for them to become ready #32774

Open Sean89us opened 1 year ago

Sean89us commented 1 year ago

Terraform Core Version

1.4.6

AWS Provider Version

v5.10.0

Affected Resource(s)

AWS VPC endpoints of type GatewayLoadBalancer

Expected Behavior

When creating a GatewayLoadBalancer type VPC endpoint, the AWS provider should wait for the VPC endpoint to reach Available status before marking it as created.

Actual Behavior

The AWS provider creates the VPC endpoint resource correctly but marks the resource as created before the endpoint reaches Available status, leading to errors when referencing the aforementioned VPC endpoint.

Context: In my example (which is to create a Palo Alto NGFW cloud endpoint), the VPC endpoint being created takes approximately 120-150 seconds to go from Pending to Available status in the AWS console.

As such, when creating a route table that routes to that endpoint, without some sort of delay (such as time_sleep) Terraform will attempt to create the route against the VPC endpoint that is still in Pending status, and it will fail with a misleading error: Route table contains unsupported route target

A second terraform apply run after the VPC endpoint is available will be successful. In order to get around this issue I am currently relying on a time_sleep block that simply waits 3 minutes, and using depends_on to force the route table creation to wait on the VPC endpoint being ready.

Relevant Error/Panic Output Snippet

Error: creating Route in Route Table (rtb-02f8e986bb0f3c207) with destination (0.0.0.0/0): RouteNotSupported: Route table contains unsupported route target: vpce-079b947c19d8fb437. VPC Endpoints of this type cannot be used as route targets.

Terraform Configuration Files

resource "aws_vpc_endpoint" "Ingress_NGFW" {
  vpc_id            = aws_vpc.warp_vpc.id
  service_name      = var.ingress_ngfwe_service_name
  subnet_ids        = [aws_subnet.ingress_ngfw.id]
  vpc_endpoint_type = "GatewayLoadBalancer"
}

resource "aws_route_table" "public_lb_route_table" {
  vpc_id     = aws_vpc.warp_vpc.id

  route {
    cidr_block      = "0.0.0.0/0"
    vpc_endpoint_id = aws_vpc_endpoint.Ingress_NGFW.id
  }
}

Steps to Reproduce

terraform apply the above code

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

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