diff --git a/README.md b/README.md index 79548e5..49f2165 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [deletion\_protection](#input\_deletion\_protection) | (Optional) Whether the ECR should have deletion protection enabled for non-empty registry. Set this to false if you intend to delete your ECR resource or namespace. NOTE: PR owner has responsibility to ensure that no other environments are sharing this ECR. Defaults to true. | `bool` | `true` | no | | [github\_actions\_prefix](#input\_github\_actions\_prefix) | String prefix for GitHub Actions variable and secrets key | `string` | `""` | no | | [github\_actions\_secret\_ecr\_access\_key](#input\_github\_actions\_secret\_ecr\_access\_key) | The name of the github actions secret containing the ECR AWS access key | `string` | `"ECR_AWS_ACCESS_KEY_ID"` | no | | [github\_actions\_secret\_ecr\_name](#input\_github\_actions\_secret\_ecr\_name) | The name of the github actions secret containing the ECR name | `string` | `"ECR_NAME"` | no | diff --git a/examples/ecr.tf b/examples/ecr.tf index 427ee4d..bc73d4b 100644 --- a/examples/ecr.tf +++ b/examples/ecr.tf @@ -69,4 +69,11 @@ module "ecr" { } EOF */ + + # OPTIONAL: Add deletion_protection = false parameter if you are planning on either deleting your environment namespace or ECR resource. + # IMPORTANT: It is the PR owners responsibility to ensure that no other environments are sharing this ECR registry. + # This flag will allow a non-empty ECR to be deleted. + # Defaults to true + + # deletion_protection = false } diff --git a/main.tf b/main.tf index f714bef..1658088 100644 --- a/main.tf +++ b/main.tf @@ -26,6 +26,7 @@ resource "aws_ecr_repository" "repo" { image_scanning_configuration { scan_on_push = var.scan_on_push } + force_delete = var.deletion_protection ? false : true } # ECR lifecycle policy diff --git a/variables.tf b/variables.tf index 717f2e5..c6032de 100644 --- a/variables.tf +++ b/variables.tf @@ -77,3 +77,9 @@ variable "github_actions_prefix" { type = string default = "" } + +variable "deletion_protection" { + description = "(Optional) Whether the ECR should have deletion protection enabled for non-empty registry. Set this to false if you intend to delete your ECR resource or namespace. NOTE: PR owner has responsibility to ensure that no other environments are sharing this ECR. Defaults to true." + type = bool + default = true +}