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 force_delete optional parameter to resource_aws_ecr_repository #9913

Merged
merged 4 commits into from
Jul 6, 2022
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
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