Model/infrastructure/terraform/modules/ecr/main.tf

45 lines
1.1 KiB
HCL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

resource "aws_ecr_repository" "my_repository" {
name = "${var.ecr_name}"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
resource "aws_ecr_lifecycle_policy" "my_repository_policy" {
repository = aws_ecr_repository.my_repository.name
policy = jsonencode({
rules = [
# 1⃣ PROTECT important environment tags forever
{
rulePriority = 1
description = "Keep prod, main, dev images forever"
selection = {
tagStatus = "tagged"
tagPrefixList = ["prod", "main", "dev"]
countType = "imageCountMoreThan"
countNumber = 9999
}
action = {
type = "retain"
}
},
# 2⃣ Expire everything else beyond the most recent 10 images
{
rulePriority = 2
description = "Retain only the last 10 images"
selection = {
tagStatus = "any"
countType = "imageCountMoreThan"
countNumber = 10
}
action = {
type = "expire"
}
}
]
})
}