Merge pull request #9050 from hashicorp/b-aws-ecr-delete-timeout

provider/aws: Add retry logic to the aws_ecr_repository delete func
This commit is contained in:
Paul Stack 2016-09-28 20:10:35 +01:00 committed by GitHub
commit 10eb572437
1 changed files with 30 additions and 1 deletions

View File

@ -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
}