diff --git a/infrastructure/terraform/modules/ecr/main.tf b/infrastructure/terraform/modules/ecr/main.tf index ee4cac11..468ef3d2 100644 --- a/infrastructure/terraform/modules/ecr/main.tf +++ b/infrastructure/terraform/modules/ecr/main.tf @@ -1,6 +1,7 @@ resource "aws_ecr_repository" "my_repository" { name = "${var.ecr_name}" image_tag_mutability = "MUTABLE" + # Allows overwriting image tags, change to IMMUTABLE if you want to prevent overwriting image_scanning_configuration { scan_on_push = true @@ -12,38 +13,10 @@ resource "aws_ecr_lifecycle_policy" "my_repository_policy" { policy = jsonencode({ rules = [ - # 1️⃣ Keep important env tags forever { rulePriority = 1 - description = "Keep prod, main, dev images forever" - selection = { - tagStatus = "tagged" - tagPrefixList = ["prod", "main", "dev"] - } - action = { - type = "retain" - } - }, - - # 2️⃣ Aggressively expire untagged images - { - rulePriority = 2 - description = "Expire untagged images" - selection = { - tagStatus = "untagged" - countType = "imageCountMoreThan" - countNumber = 1 - } - action = { - type = "expire" - } - }, - - # 3️⃣ Rotate everything else - { - rulePriority = 3 description = "Retain only the last 10 images" - selection = { + selection = { tagStatus = "any" countType = "imageCountMoreThan" countNumber = 10 @@ -54,4 +27,4 @@ resource "aws_ecr_lifecycle_policy" "my_repository_policy" { } ] }) -} +} \ No newline at end of file