Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout retries for ECR resources #9079

Merged
merged 3 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions aws/resource_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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("")
Expand Down Expand Up @@ -143,20 +147,24 @@ 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
}
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)
}
ryndaniels marked this conversation as resolved.
Show resolved Hide resolved

if err != nil {
return fmt.Errorf("error deleting ECR repository: %s", err)
}
Expand Down
19 changes: 13 additions & 6 deletions aws/resource_aws_ecr_repository_policy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"fmt"
"log"
"time"

Expand Down Expand Up @@ -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") {
Expand All @@ -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
Expand Down Expand Up @@ -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") {
Expand All @@ -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
Expand Down