Skip to content

Commit

Permalink
Remove extra retry and cleanup errors for deleting api gateway resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ryndaniels committed Jun 19, 2019
1 parent 54e88b1 commit 55f13f5
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions aws/resource_aws_api_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -145,29 +143,18 @@ func resourceAwsApiGatewayResourceDelete(d *schema.ResourceData, meta interface{
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Resource: %s", d.Id())

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
log.Printf("[DEBUG] schema is %#v", d)
_, err := conn.DeleteResource(&apigateway.DeleteResourceInput{
ResourceId: aws.String(d.Id()),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
})
if err == nil {
return nil
}

if apigatewayErr, ok := err.(awserr.Error); ok && apigatewayErr.Code() == "NotFoundException" {
return nil
}

return resource.NonRetryableError(err)
log.Printf("[DEBUG] schema is %#v", d)
_, err := conn.DeleteResource(&apigateway.DeleteResourceInput{
ResourceId: aws.String(d.Id()),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
})

if isResourceTimeoutError(err) {
_, err = conn.DeleteResource(&apigateway.DeleteResourceInput{
ResourceId: aws.String(d.Id()),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
})
if isAWSErr(err, apigateway.ErrCodeNotFoundException, "") {
return nil
}

return err
if err != nil {
return fmt.Errorf("Error deleting API Gateway Resource: %s", err)
}
return nil
}

0 comments on commit 55f13f5

Please sign in to comment.