untagged image as well

This commit is contained in:
Jun-te Kim 2026-02-02 23:26:42 +00:00
parent 8b0ac85ad1
commit 6ba5ecc3b4

View file

@ -12,7 +12,7 @@ resource "aws_ecr_lifecycle_policy" "my_repository_policy" {
policy = jsonencode({
rules = [
# 1 PROTECT important environment tags forever
# 1 Keep important env tags forever
{
rulePriority = 1
description = "Keep prod, main, dev images forever"
@ -25,9 +25,23 @@ resource "aws_ecr_lifecycle_policy" "my_repository_policy" {
}
},
# 2 Expire everything else beyond the most recent 10 images
# 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 = {
tagStatus = "any"
@ -41,4 +55,3 @@ resource "aws_ecr_lifecycle_policy" "my_repository_policy" {
]
})
}