aws: Retry ecs_cluster deletion if instances or services are active

This commit is contained in:
Radek Simko 2015-07-12 11:30:16 +01:00
parent 206278bac0
commit 37d10ebf37
1 changed files with 28 additions and 8 deletions

View File

@ -2,9 +2,12 @@ package aws
import ( import (
"log" "log"
"time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -67,14 +70,31 @@ func resourceAwsEcsClusterDelete(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Deleting ECS cluster %s", d.Id()) log.Printf("[DEBUG] Deleting ECS cluster %s", d.Id())
// TODO: Handle ClientException: The Cluster cannot be deleted while Container Instances are active. return resource.Retry(10*time.Minute, func() error {
// TODO: Handle ClientException: The Cluster cannot be deleted while Services are active.
out, err := conn.DeleteCluster(&ecs.DeleteClusterInput{ out, err := conn.DeleteCluster(&ecs.DeleteClusterInput{
Cluster: aws.String(d.Id()), Cluster: aws.String(d.Id()),
}) })
if err == nil {
log.Printf("[DEBUG] ECS cluster %s deleted: %#v", d.Id(), out) log.Printf("[DEBUG] ECS cluster %s deleted: %#v", d.Id(), out)
return nil
}
awsErr, ok := err.(awserr.Error)
if !ok {
return resource.RetryError{Err: err}
}
if awsErr.Code() == "ClusterContainsContainerInstancesException" {
log.Printf("[TRACE] Retrying ECS cluster %q deletion after %q", d.Id(), awsErr.Code())
return err return err
} }
if awsErr.Code() == "ClusterContainsServicesException" {
log.Printf("[TRACE] Retrying ECS cluster %q deletion after %q", d.Id(), awsErr.Code())
return err
}
return resource.RetryError{Err: err}
})
}