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

Add retry mechanism and timeout when reading ecr_repository #3910

Merged
merged 1 commit into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 22 additions & 3 deletions aws/resource_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func resourceAwsEcrRepository() *schema.Resource {
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(1 * time.Minute),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our current practice is to hardcode eventual consistency timeouts so will remove this configurable timeout here. If we are changing this practice, we should do so everywhere.

Delete: schema.DefaultTimeout(20 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -72,11 +77,25 @@ func resourceAwsEcrRepositoryRead(d *schema.ResourceData, meta interface{}) erro
conn := meta.(*AWSClient).ecrconn

log.Printf("[DEBUG] Reading repository %s", d.Id())
out, err := conn.DescribeRepositories(&ecr.DescribeRepositoriesInput{
var out *ecr.DescribeRepositoriesOutput
input := &ecr.DescribeRepositoriesInput{
RepositoryNames: []*string{aws.String(d.Id())},
}

err := resource.Retry(d.Timeout(schema.TimeoutRead), func() *resource.RetryError {
var err error
out, err = conn.DescribeRepositories(input)
if err != nil {
if d.IsNewResource() && isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})

if err != nil {
if ecrerr, ok := err.(awserr.Error); ok && ecrerr.Code() == "RepositoryNotFoundException" {
if !d.IsNewResource() && isAWSErr(err, ecr.ErrCodeRepositoryNotFoundException, "") {
d.SetId("")
return nil
}
Expand Down Expand Up @@ -119,7 +138,7 @@ func resourceAwsEcrRepositoryDelete(d *schema.ResourceData, meta interface{}) er
}

log.Printf("[DEBUG] Waiting for ECR Repository %q to be deleted", d.Id())
err = resource.Retry(20*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
_, err := conn.DescribeRepositories(&ecr.DescribeRepositoriesInput{
RepositoryNames: []*string{aws.String(d.Id())},
})
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/ecr_repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ In addition to all arguments above, the following attributes are exported:
* `registry_id` - The registry ID where the repository was created.
* `repository_url` - The URL of the repository (in the form `aws_account_id.dkr.ecr.region.amazonaws.com/repositoryName`

## Timeouts

`aws_ecr_repository` provides the following [Timeouts](/docs/configuration/resources.html#timeouts)
configuration options:

- `read` - (Default `1 minute`) How long to wait for a repository to be listed after creation.
- `delete` - (Default `20 minutes`) How long to wait for a repository to be deleted.

## Import

Expand Down