Skip to content

Commit

Permalink
Add force_delete optional parameter to resource_aws_ecr_repository
Browse files Browse the repository at this point in the history
  • Loading branch information
yeforriak authored and gdavison committed Jun 8, 2022
1 parent 9a6da4f commit 098d4f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 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 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 098d4f7

Please sign in to comment.