aws: Wait for ECS service to be drained before deletion

This commit is contained in:
Radek Simko 2015-12-17 15:21:05 +01:00
parent 583c0a54c4
commit f8bb48b287
1 changed files with 28 additions and 7 deletions

View File

@ -279,13 +279,33 @@ func resourceAwsEcsServiceDelete(d *schema.ResourceData, meta interface{}) error
}
}
input := ecs.DeleteServiceInput{
Service: aws.String(d.Id()),
Cluster: aws.String(d.Get("cluster").(string)),
}
// Wait until the ECS service is drained
err = resource.Retry(5*time.Minute, func() error {
input := ecs.DeleteServiceInput{
Service: aws.String(d.Id()),
Cluster: aws.String(d.Get("cluster").(string)),
}
log.Printf("[DEBUG] Deleting ECS service %s", input)
out, err := conn.DeleteService(&input)
log.Printf("[DEBUG] Trying to delete ECS service %s", input)
_, err := conn.DeleteService(&input)
if err == nil {
return nil
}
ec2err, ok := err.(awserr.Error)
if !ok {
return &resource.RetryError{Err: err}
}
if ec2err.Code() == "InvalidParameterException" {
// Prevent "The service cannot be stopped while deployments are active."
log.Printf("[DEBUG] Trying to delete ECS service again: %q",
ec2err.Message())
return err
}
return &resource.RetryError{Err: err}
})
if err != nil {
return err
}
@ -306,6 +326,7 @@ func resourceAwsEcsServiceDelete(d *schema.ResourceData, meta interface{}) error
return resp, "FAILED", err
}
log.Printf("[DEBUG] ECS service %s is currently %q", *resp.Services[0].Status)
return resp, *resp.Services[0].Status, nil
},
}
@ -315,7 +336,7 @@ func resourceAwsEcsServiceDelete(d *schema.ResourceData, meta interface{}) error
return err
}
log.Printf("[DEBUG] ECS service %s deleted.", *out.Service.ServiceArn)
log.Printf("[DEBUG] ECS service %s deleted.", d.Id())
return nil
}