Skip to content

Commit

Permalink
Merge pull request #3387 from terraform-providers/b-ecs-retry-read-on…
Browse files Browse the repository at this point in the history
…-creation

resource/aws_ecs_service: Retry DescribeServices after creation
  • Loading branch information
radeksimko authored Feb 15, 2018
2 parents 085b946 + 2882fff commit 40b6110
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,24 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error {
}
return resource.NonRetryableError(err)
}

if d.IsNewResource() && len(out.Services) < 1 {
return resource.RetryableError(fmt.Errorf("No ECS service found: %q", d.Id()))
}

service := out.Services[0]
if d.IsNewResource() && *service.Status == "INACTIVE" {
return resource.RetryableError(fmt.Errorf("ECS service currently INACTIVE: %q", d.Id()))
}

return nil
})
if err != nil {
return err
}

if len(out.Services) < 1 {
log.Printf("[DEBUG] Removing ECS service %s (%s) because it's gone", d.Get("name").(string), d.Id())
log.Printf("[WARN] Removing ECS service %s (%s) because it's gone", d.Get("name").(string), d.Id())
d.SetId("")
return nil
}
Expand All @@ -372,7 +382,7 @@ func resourceAwsEcsServiceRead(d *schema.ResourceData, meta interface{}) error {

// Status==INACTIVE means deleted service
if *service.Status == "INACTIVE" {
log.Printf("[DEBUG] Removing ECS service %q because it's INACTIVE", *service.ServiceArn)
log.Printf("[WARN] Removing ECS service %q because it's INACTIVE", *service.ServiceArn)
d.SetId("")
return nil
}
Expand Down

0 comments on commit 40b6110

Please sign in to comment.