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

provider/aws: Add retry logic to the aws_ecr_repository delete func #9050

Merged
merged 1 commit into from
Sep 28, 2016
Merged
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
31 changes: 30 additions & 1 deletion builtin/providers/aws/resource_aws_ecr_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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()))
})
Copy link
Contributor

@catsby catsby Sep 27, 2016

Choose a reason for hiding this comment

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

We don't check the err from resource.Retry here, so if the time limit hits we still remove from state, is that correct behavior? If you hit any of the resource.NonRetryableError paths then we'll still remove from state because we don't check the error

if err != nil {
return err
}

d.SetId("")
log.Printf("[DEBUG] repository %q deleted.", d.Get("name").(string))

return nil
}