Skip to content

Commit

Permalink
provider/aws: Retry ECS service update on InvalidParameterException (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored and stack72 committed May 21, 2017
1 parent 030f26b commit 3a41e45
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions builtin/providers/aws/resource_aws_ecs_service.go
Expand Up @@ -230,13 +230,13 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error
out, err = conn.CreateService(&input)

if err != nil {
ec2err, ok := err.(awserr.Error)
awsErr, ok := err.(awserr.Error)
if !ok {
return resource.NonRetryableError(err)
}
if ec2err.Code() == "InvalidParameterException" {
if awsErr.Code() == "InvalidParameterException" {
log.Printf("[DEBUG] Trying to create ECS service again: %q",
ec2err.Message())
awsErr.Message())
return resource.RetryableError(err)
}

Expand Down Expand Up @@ -400,12 +400,26 @@ func resourceAwsEcsServiceUpdate(d *schema.ResourceData, meta interface{}) error
}
}

out, err := conn.UpdateService(&input)
// Retry due to AWS IAM policy eventual consistency
// See https://github.com/hashicorp/terraform/issues/4375
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
out, err := conn.UpdateService(&input)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == "InvalidParameterException" {
log.Printf("[DEBUG] Trying to update ECS service again: %#v", err)
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}

log.Printf("[DEBUG] Updated ECS service %s", out.Service)
return nil
})
if err != nil {
return err
}
service := out.Service
log.Printf("[DEBUG] Updated ECS service %s", service)

return resourceAwsEcsServiceRead(d, meta)
}
Expand Down

0 comments on commit 3a41e45

Please sign in to comment.