Skip to content
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

VPCLink creation issues (NLB is already associated with another VPC Endpoint Service) #12796

Closed
Brother-Andy opened this issue Apr 13, 2020 · 4 comments · Fixed by #18382
Closed
Labels
bug Addresses a defect in current functionality. service/apigateway Issues and PRs that pertain to the apigateway service.
Milestone

Comments

@Brother-Andy
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.21
aws provider version 2.54.0

Affected Resource(s)

aws_api_gateway_vpc_link

Terraform Configuration Files

resource "aws_api_gateway_vpc_link" "main" {
  name        = "vpclink-myconnector"
  target_arns = [aws_lb.example.arn]
}

Expected Behavior

I have a load balancer that has already been attached to the vpclink.
I want to provision a new vpclink resource with the same balancer.
Terraform should fail with the appropriate error and write vpclink resource to the state file (since it has been provisioned but failed to start).
terraform destroy command should remove failed vpclink

Actual Behavior

When I try to attach NLB to the new VPCLink using terraform I receive an error:

Error: Error waiting for APIGateway Vpc Link status to be "AVAILABLE": unexpected state 'FAILED', wanted target 'AVAILABLE'. last error: %!s(<nil>)

  on main.tf line 17, in resource "aws_api_gateway_vpc_link" "main":
  17: resource "aws_api_gateway_vpc_link" "main" {

In fact API Gateway console returns a more convenient error:
VPC link creation failed
NLB is already associated with another VPC Endpoint Service.

When I execute terraform destroy, it does not remove failed VPCLink resource since information about its provisioning wasn't added to the state file (I guess because of error).

Steps to Reproduce

  1. Create vpclink A and attach a balancer to it.
  2. Create vpclink B and attach the same balancer to it (terraform apply).
  3. Receive an error.
  4. Execute terraform destroy
  5. Check console and make sure that failed vpclink is still there.
@ghost ghost added the service/apigateway Issues and PRs that pertain to the apigateway service. label Apr 13, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 13, 2020
@ewbankkit
Copy link
Contributor

ewbankkit commented Apr 13, 2020

My guess is that it's the d.SetId("") here that is at fault:

stateConf := &resource.StateChangeConf{
Pending: []string{apigateway.VpcLinkStatusPending},
Target: []string{apigateway.VpcLinkStatusAvailable},
Refresh: apigatewayVpcLinkRefreshStatusFunc(conn, *resp.Id),
Timeout: 8 * time.Minute,
MinTimeout: 3 * time.Second,
}
_, err = stateConf.WaitForState()
if err != nil {
d.SetId("")
return fmt.Errorf("Error waiting for APIGateway Vpc Link status to be \"%s\": %s", apigateway.VpcLinkStatusAvailable, err)
}

The VPC link has been created but does not reach the Available state because of the stated error but we are unsetting the ID of the create resource which means it isn't stored to the state file.

@trahloff-deloitte
Copy link

+1 @ewbankkit's suspicion.

This also leads to Terraform creating a new (failing) VPC Link for each apply because the created VPC Link is not persisted into the state.

@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 24, 2021
@github-actions github-actions bot added this to the v3.34.0 milestone Mar 24, 2021
@ghost
Copy link

ghost commented Mar 26, 2021

This has been released in version 3.34.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 for triage. Thanks!

@ghost
Copy link

ghost commented Apr 24, 2021

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/apigateway Issues and PRs that pertain to the apigateway service.
Projects
None yet
3 participants