Skip to content

Commit

Permalink
Merge pull request #9913 from yeforriak/issue-9911_ecr-force-delete
Browse files Browse the repository at this point in the history
Add force_delete optional parameter to resource_aws_ecr_repository
  • Loading branch information
gdavison authored Jul 6, 2022
2 parents 7a4ca21 + c96691e commit 97bc5a2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/9913.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ecr_repository: Add `force_delete` parameter.
```
13 changes: 10 additions & 3 deletions internal/service/ecr/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func ResourceRepository() *schema.Resource {
DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock,
ForceNew: true,
},
"force_delete": {
Type: schema.TypeBool,
Optional: true,
},
"image_scanning_configuration": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -346,13 +350,16 @@ func resourceRepositoryDelete(d *schema.ResourceData, meta interface{}) error {
_, err := conn.DeleteRepository(&ecr.DeleteRepositoryInput{
RepositoryName: aws.String(d.Id()),
RegistryId: aws.String(d.Get("registry_id").(string)),
Force: aws.Bool(true),
Force: aws.Bool(d.Get("force_delete").(bool)),
})
if err != nil {
if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotFoundException) {
return nil
}
return fmt.Errorf("error deleting ECR repository: %s", err)
if tfawserr.ErrCodeEquals(err, ecr.ErrCodeRepositoryNotEmptyException) {
return fmt.Errorf("ECR Repository (%s) not empty, consider using force_delete: %w", d.Id(), err)
}
return fmt.Errorf("error deleting ECR Repository (%s): %w", d.Id(), err)
}

log.Printf("[DEBUG] Waiting for ECR Repository %q to be deleted", d.Id())
Expand All @@ -368,7 +375,7 @@ func resourceRepositoryDelete(d *schema.ResourceData, meta interface{}) error {
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("ECR Repository (%s) still exists", d.Id()))
})
if tfresource.TimedOut(err) {
_, err = conn.DescribeRepositories(input)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/ecr_repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The following arguments are supported:

* `name` - (Required) Name of the repository.
* `encryption_configuration` - (Optional) Encryption configuration for the repository. See [below for schema](#encryption_configuration).
* `force_delete` - (Optional) If `true`, will delete the repository even if it contains images.
Defaults to `false`.
* `image_tag_mutability` - (Optional) The tag mutability setting for the repository. Must be one of: `MUTABLE` or `IMMUTABLE`. Defaults to `MUTABLE`.
* `image_scanning_configuration` - (Optional) Configuration block that defines image scanning configuration for the repository. By default, image scanning must be manually triggered. See the [ECR User Guide](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html) for more information about image scanning.
* `scan_on_push` - (Required) Indicates whether images are scanned after being pushed to the repository (true) or not scanned (false).
Expand Down

0 comments on commit 97bc5a2

Please sign in to comment.