Skip to content

Commit

Permalink
Merge pull request #2393 from betabandido/fix/method-response-conflict
Browse files Browse the repository at this point in the history
Fix conflict exception in API gateway method response
  • Loading branch information
Ninir authored Nov 21, 2017
2 parents 027524d + 215add6 commit a61a091
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions aws/resource_aws_api_gateway_method_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"sync"
)

var resourceAwsApiGatewayMethodResponseMutex = &sync.Mutex{}

func resourceAwsApiGatewayMethodResponse() *schema.Resource {
return &schema.Resource{
Create: resourceAwsApiGatewayMethodResponseCreate,
Expand Down Expand Up @@ -93,14 +96,20 @@ func resourceAwsApiGatewayMethodResponseCreate(d *schema.ResourceData, meta inte
}
}

_, err := conn.PutMethodResponse(&apigateway.PutMethodResponseInput{
HttpMethod: aws.String(d.Get("http_method").(string)),
ResourceId: aws.String(d.Get("resource_id").(string)),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
StatusCode: aws.String(d.Get("status_code").(string)),
ResponseModels: aws.StringMap(models),
ResponseParameters: aws.BoolMap(parameters),
resourceAwsApiGatewayMethodResponseMutex.Lock()
defer resourceAwsApiGatewayMethodResponseMutex.Unlock()

_, err := retryOnAwsCode(apigateway.ErrCodeConflictException, func() (interface{}, error) {
return conn.PutMethodResponse(&apigateway.PutMethodResponseInput{
HttpMethod: aws.String(d.Get("http_method").(string)),
ResourceId: aws.String(d.Get("resource_id").(string)),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
StatusCode: aws.String(d.Get("status_code").(string)),
ResponseModels: aws.StringMap(models),
ResponseParameters: aws.BoolMap(parameters),
})
})

if err != nil {
return fmt.Errorf("Error creating API Gateway Method Response: %s", err)
}
Expand Down

0 comments on commit a61a091

Please sign in to comment.