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

Add Timeouts block to aws api gw vpc link resource #10407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions aws/resource_aws_api_gateway_vpc_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ func resourceAwsApiGatewayVpcLink() *schema.Resource {
Read: resourceAwsApiGatewayVpcLinkRead,
Update: resourceAwsApiGatewayVpcLinkUpdate,
Delete: resourceAwsApiGatewayVpcLinkDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(8 * time.Minute),
Update: schema.DefaultTimeout(8 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -63,7 +70,7 @@ func resourceAwsApiGatewayVpcLinkCreate(d *schema.ResourceData, meta interface{}
Pending: []string{apigateway.VpcLinkStatusPending},
Target: []string{apigateway.VpcLinkStatusAvailable},
Refresh: apigatewayVpcLinkRefreshStatusFunc(conn, *resp.Id),
Timeout: 8 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
MinTimeout: 3 * time.Second,
}

Expand Down Expand Up @@ -139,7 +146,7 @@ func resourceAwsApiGatewayVpcLinkUpdate(d *schema.ResourceData, meta interface{}
Pending: []string{apigateway.VpcLinkStatusPending},
Target: []string{apigateway.VpcLinkStatusAvailable},
Refresh: apigatewayVpcLinkRefreshStatusFunc(conn, d.Id()),
Timeout: 8 * time.Minute,
Timeout: d.Timeout(schema.TimeoutUpdate),
MinTimeout: 3 * time.Second,
}

Expand Down Expand Up @@ -168,7 +175,7 @@ func resourceAwsApiGatewayVpcLinkDelete(d *schema.ResourceData, meta interface{}
return fmt.Errorf("error deleting API Gateway VPC Link (%s): %s", d.Id(), err)
}

if err := waitForApiGatewayVpcLinkDeletion(conn, d.Id()); err != nil {
if err := waitForApiGatewayVpcLinkDeletion(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return fmt.Errorf("error waiting for API Gateway VPC Link (%s) deletion: %s", d.Id(), err)
}

Expand All @@ -188,13 +195,13 @@ func apigatewayVpcLinkRefreshStatusFunc(conn *apigateway.APIGateway, vl string)
}
}

func waitForApiGatewayVpcLinkDeletion(conn *apigateway.APIGateway, vpcLinkID string) error {
func waitForApiGatewayVpcLinkDeletion(conn *apigateway.APIGateway, vpcLinkID string, timeout time.Duration) error {
stateConf := resource.StateChangeConf{
Pending: []string{apigateway.VpcLinkStatusPending,
apigateway.VpcLinkStatusAvailable,
apigateway.VpcLinkStatusDeleting},
Target: []string{""},
Timeout: 5 * time.Minute,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @philippevidal80 👋 Thank you for this contribution.

This is situation where increasing the encoded timeout to match the API behavior feels more appropriate, rather than introducing new configuration, since the API operation does not have any operator managed scaling factor (such as data size, etc.). Please see the issue comments for more context.

Can you please revert all the changes and just increase the timeouts to 20 (or 30) minutes? We can get this merged immediately afterwards. Thanks!

Timeout: timeout,
MinTimeout: 1 * time.Second,
Refresh: func() (interface{}, string, error) {
resp, err := conn.GetVpcLink(&apigateway.GetVpcLinkInput{
Expand Down
3 changes: 2 additions & 1 deletion aws/resource_aws_api_gateway_vpc_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apigateway"
Expand Down Expand Up @@ -41,7 +42,7 @@ func testSweepAPIGatewayVpcLinks(region string) error {
continue
}

if err := waitForApiGatewayVpcLinkDeletion(conn, id); err != nil {
if err := waitForApiGatewayVpcLinkDeletion(conn, id, 20*time.Minute); err != nil {
log.Printf("[ERROR] Error waiting for API Gateway VPC Link (%s) deletion: %s", id, err)
}
}
Expand Down