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

Cleanup around resource.Retry methods for various api gateway resources #9068

Merged
merged 1 commit into from
Jun 21, 2019
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
3 changes: 3 additions & 0 deletions aws/resource_aws_api_gateway_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func resourceAwsApiGatewayAccountUpdate(d *schema.ResourceData, meta interface{}

return nil
})
if isResourceTimeoutError(err) {
out, err = conn.UpdateAccount(&input)
}
if err != nil {
return fmt.Errorf("Updating API Gateway Account failed: %s", err)
}
Expand Down
17 changes: 11 additions & 6 deletions aws/resource_aws_api_gateway_base_path_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ func resourceAwsApiGatewayBasePathMapping() *schema.Resource {

func resourceAwsApiGatewayBasePathMappingCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigateway
input := &apigateway.CreateBasePathMappingInput{
RestApiId: aws.String(d.Get("api_id").(string)),
DomainName: aws.String(d.Get("domain_name").(string)),
BasePath: aws.String(d.Get("base_path").(string)),
Stage: aws.String(d.Get("stage_name").(string)),
}

err := resource.Retry(30*time.Second, func() *resource.RetryError {
_, err := conn.CreateBasePathMapping(&apigateway.CreateBasePathMappingInput{
RestApiId: aws.String(d.Get("api_id").(string)),
DomainName: aws.String(d.Get("domain_name").(string)),
BasePath: aws.String(d.Get("base_path").(string)),
Stage: aws.String(d.Get("stage_name").(string)),
})
_, err := conn.CreateBasePathMapping(input)

if err != nil {
if err, ok := err.(awserr.Error); ok && err.Code() != "BadRequestException" {
Expand All @@ -73,6 +74,10 @@ func resourceAwsApiGatewayBasePathMappingCreate(d *schema.ResourceData, meta int
return nil
})

if isResourceTimeoutError(err) {
_, err = conn.CreateBasePathMapping(input)
}

if err != nil {
return fmt.Errorf("Error creating Gateway base path mapping: %s", err)
}
Expand Down
23 changes: 10 additions & 13 deletions aws/resource_aws_api_gateway_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"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"
"github.com/hashicorp/terraform/helper/validation"
)
Expand Down Expand Up @@ -294,19 +293,17 @@ func resourceAwsApiGatewayDomainNameDelete(d *schema.ResourceData, meta interfac
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Domain Name: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteDomainName(&apigateway.DeleteDomainNameInput{
DomainName: aws.String(d.Id()),
})
_, err := conn.DeleteDomainName(&apigateway.DeleteDomainNameInput{
DomainName: aws.String(d.Id()),
})

if err == nil {
return nil
}
if isAWSErr(err, "NotFoundException", "") {
return nil
}

if apigatewayErr, ok := err.(awserr.Error); ok && apigatewayErr.Code() == "NotFoundException" {
return nil
}
if err != nil {
return fmt.Errorf("Error deleting API Gateway domain name: %s", err)
}

return resource.NonRetryableError(err)
})
return nil
}
29 changes: 11 additions & 18 deletions aws/resource_aws_api_gateway_gateway_response.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 @@ -139,22 +137,17 @@ func resourceAwsApiGatewayGatewayResponseDelete(d *schema.ResourceData, meta int
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Gateway Response: %s", d.Id())

return resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteGatewayResponse(&apigateway.DeleteGatewayResponseInput{
RestApiId: aws.String(d.Get("rest_api_id").(string)),
ResponseType: aws.String(d.Get("response_type").(string)),
})

if err == nil {
return nil
}

apigatewayErr, ok := err.(awserr.Error)
_, err := conn.DeleteGatewayResponse(&apigateway.DeleteGatewayResponseInput{
RestApiId: aws.String(d.Get("rest_api_id").(string)),
ResponseType: aws.String(d.Get("response_type").(string)),
})

if ok && apigatewayErr.Code() == "NotFoundException" {
return nil
}
if isAWSErr(err, "NotFoundException", "") {
return nil
}

return resource.NonRetryableError(err)
})
if err != nil {
return fmt.Errorf("Error deleting API Gateway gateway response: %s", err)
}
return nil
}
34 changes: 13 additions & 21 deletions aws/resource_aws_api_gateway_model.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 @@ -172,26 +170,20 @@ func resourceAwsApiGatewayModelUpdate(d *schema.ResourceData, meta interface{})
func resourceAwsApiGatewayModelDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).apigateway
log.Printf("[DEBUG] Deleting API Gateway Model: %s", d.Id())
input := &apigateway.DeleteModelInput{
ModelName: aws.String(d.Get("name").(string)),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
}

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

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

if !ok {
return resource.NonRetryableError(err)
}
if isAWSErr(err, "NotFoundException", "") {
return nil
}

return resource.NonRetryableError(err)
})
if err != nil {
return fmt.Errorf("Error deleting API gateway model: %s", err)
}
return nil
}
19 changes: 8 additions & 11 deletions aws/resource_aws_api_gateway_usage_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"fmt"
"log"
"strconv"
"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"
"github.com/hashicorp/terraform/helper/validation"
)
Expand Down Expand Up @@ -491,15 +489,14 @@ func resourceAwsApiGatewayUsagePlanDelete(d *schema.ResourceData, meta interface

log.Printf("[DEBUG] Deleting API Gateway Usage Plan: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteUsagePlan(&apigateway.DeleteUsagePlanInput{
UsagePlanId: aws.String(d.Id()),
})
_, err := conn.DeleteUsagePlan(&apigateway.DeleteUsagePlanInput{
UsagePlanId: aws.String(d.Id()),
})

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

return nil

return resource.NonRetryableError(err)
})
}
26 changes: 11 additions & 15 deletions aws/resource_aws_api_gateway_usage_plan_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package aws
import (
"fmt"
"log"
"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 @@ -97,19 +95,17 @@ func resourceAwsApiGatewayUsagePlanKeyDelete(d *schema.ResourceData, meta interf
conn := meta.(*AWSClient).apigateway

log.Printf("[DEBUG] Deleting API Gateway Usage Plan Key: %s", d.Id())
_, err := conn.DeleteUsagePlanKey(&apigateway.DeleteUsagePlanKeyInput{
UsagePlanId: aws.String(d.Get("usage_plan_id").(string)),
KeyId: aws.String(d.Get("key_id").(string)),
})
if isAWSErr(err, "NotFoundException", "") {
return nil
}
if err != nil {
return fmt.Errorf("Error deleting API Gateway usage plan key: %s", err)
}

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteUsagePlanKey(&apigateway.DeleteUsagePlanKeyInput{
UsagePlanId: aws.String(d.Get("usage_plan_id").(string)),
KeyId: aws.String(d.Get("key_id").(string)),
})
if err == nil {
return nil
}
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "NotFoundException" {
return nil
}
return nil

return resource.NonRetryableError(err)
})
}