diff --git a/aws/resource_aws_ecr_repository.go b/aws/resource_aws_ecr_repository.go index 52709fcf963..2b22b1a37ad 100644 --- a/aws/resource_aws_ecr_repository.go +++ b/aws/resource_aws_ecr_repository.go @@ -81,8 +81,8 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro RepositoryNames: aws.StringSlice([]string{d.Id()}), } - err := resource.Retry(1*time.Minute, func() *resource.RetryError { - var err error + var err error + err = resource.Retry(1*time.Minute, func() *resource.RetryError { out, err = conn.DescribeRepositories(input) if d.IsNewResource() && isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") { return resource.RetryableError(err) @@ -93,6 +93,10 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro return nil }) + if isResourceTimeoutError(err) { + out, err = conn.DescribeRepositories(input) + } + if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") { log.Printf("[WARN] ECR Repository (%s) not found, removing from state", d.Id()) d.SetId("") @@ -143,10 +147,11 @@ func resourceAwsEcrRepositoryDelete(d *schema.ResourceData, meta interface{}) er } log.Printf("[DEBUG] Waiting for ECR Repository %q to be deleted", d.Id()) + input := &ecr.DescribeRepositoriesInput{ + RepositoryNames: aws.StringSlice([]string{d.Id()}), + } err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { - _, err := conn.DescribeRepositories(&ecr.DescribeRepositoriesInput{ - RepositoryNames: aws.StringSlice([]string{d.Id()}), - }) + _, err = conn.DescribeRepositories(input) if err != nil { if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") { return nil @@ -154,9 +159,16 @@ func resourceAwsEcrRepositoryDelete(d *schema.ResourceData, meta interface{}) er return resource.NonRetryableError(err) } - return resource.RetryableError( - fmt.Errorf("%q: Timeout while waiting for the ECR Repository to be deleted", d.Id())) + return resource.RetryableError(fmt.Errorf("%q: Timeout while waiting for the ECR Repository to be deleted", d.Id())) }) + if isResourceTimeoutError(err) { + _, err = conn.DescribeRepositories(input) + } + + if isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") { + return nil + } + if err != nil { return fmt.Errorf("error deleting ECR repository: %s", err) } diff --git a/aws/resource_aws_ecr_repository_policy.go b/aws/resource_aws_ecr_repository_policy.go index c661ed1140c..c19f95e1455 100644 --- a/aws/resource_aws_ecr_repository_policy.go +++ b/aws/resource_aws_ecr_repository_policy.go @@ -1,6 +1,7 @@ package aws import ( + "fmt" "log" "time" @@ -51,9 +52,9 @@ func resourceAwsEcrRepositoryPolicyCreate(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Creating ECR resository policy: %s", input) // Retry due to IAM eventual consistency + var err error var out *ecr.SetRepositoryPolicyOutput - err := resource.Retry(2*time.Minute, func() *resource.RetryError { - var err error + err = resource.Retry(2*time.Minute, func() *resource.RetryError { out, err = conn.SetRepositoryPolicy(&input) if isAWSErr(err, "InvalidParameterException", "Invalid repository policy provided") { @@ -62,8 +63,11 @@ func resourceAwsEcrRepositoryPolicyCreate(d *schema.ResourceData, meta interface } return resource.NonRetryableError(err) }) + if isResourceTimeoutError(err) { + out, err = conn.SetRepositoryPolicy(&input) + } if err != nil { - return err + return fmt.Errorf("Error creating ECR Repository Policy: %s", err) } repositoryPolicy := *out @@ -124,9 +128,9 @@ func resourceAwsEcrRepositoryPolicyUpdate(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Updating ECR resository policy: %s", input) // Retry due to IAM eventual consistency + var err error var out *ecr.SetRepositoryPolicyOutput - err := resource.Retry(2*time.Minute, func() *resource.RetryError { - var err error + err = resource.Retry(2*time.Minute, func() *resource.RetryError { out, err = conn.SetRepositoryPolicy(&input) if isAWSErr(err, "InvalidParameterException", "Invalid repository policy provided") { @@ -135,8 +139,11 @@ func resourceAwsEcrRepositoryPolicyUpdate(d *schema.ResourceData, meta interface } return resource.NonRetryableError(err) }) + if isResourceTimeoutError(err) { + out, err = conn.SetRepositoryPolicy(&input) + } if err != nil { - return err + return fmt.Errorf("Error updating ECR Repository Policy: %s", err) } repositoryPolicy := *out