diff --git a/builtin/providers/aws/resource_aws_ecr_repository.go b/builtin/providers/aws/resource_aws_ecr_repository.go index 4be941e02..ce873e752 100644 --- a/builtin/providers/aws/resource_aws_ecr_repository.go +++ b/builtin/providers/aws/resource_aws_ecr_repository.go @@ -2,12 +2,14 @@ package aws import ( "log" + "time" "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ecr" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -117,7 +119,34 @@ func resourceAwsEcrRepositoryDelete(d *schema.ResourceData, meta interface{}) er return err } - log.Printf("[DEBUG] repository %q deleted.", d.Get("arn").(string)) + log.Printf("[DEBUG] Waiting for ECR Repository %q to be deleted", d.Id()) + err = resource.Retry(20*time.Minute, func() *resource.RetryError { + _, err := conn.DescribeRepositories(&ecr.DescribeRepositoriesInput{ + RepositoryNames: []*string{aws.String(d.Id())}, + }) + + if err != nil { + awsErr, ok := err.(awserr.Error) + if !ok { + return resource.NonRetryableError(err) + } + + if awsErr.Code() == "RepositoryNotFoundException" { + return nil + } + + return resource.NonRetryableError(err) + } + + return resource.RetryableError( + fmt.Errorf("%q: Timeout while waiting for the ECR Repository to be deleted", d.Id())) + }) + if err != nil { + return err + } + + d.SetId("") + log.Printf("[DEBUG] repository %q deleted.", d.Get("name").(string)) return nil }