Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 62 additions & 23 deletions terraform/modules/01.ecr/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,49 @@ resource "aws_ecr_repository" "notification_repository" {
}


# Política de ciclo de vida para manter apenas as últimas 1 imagens
# Política de ciclo de vida otimizada para manter apenas 1 imagem por tag
resource "aws_ecr_lifecycle_policy" "api_repository_policy" {
repository = aws_ecr_repository.api_repository.name

policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Manter apenas as últimas 1 imagens para otimizar custos"
rulePriority = 1
description = "Remove imagens não-taggeadas imediatamente (exceto a mais recente)"
selection = {
tagStatus = "untagged"
countType = "imageCountMoreThan"
countNumber = 1
tagStatus = "untagged"
countType = "imageCountMoreThan"
countNumber = 1
}
action = {
type = "expire"
}
},
{
rulePriority = 2
description = "Manter apenas as últimas 1 imagens taggeadas"
description = "Mantém apenas 1 imagem por tag específica - remove versões antigas"
selection = {
tagStatus = "tagged"
tagPrefixList = ["latest", "v", "dev", "prod", "staging"]
tagPrefixList = ["latest", "v", "dev", "prod", "staging", "main"]
countType = "imageCountMoreThan"
countNumber = 1
}
action = {
type = "expire"
}
},
{
rulePriority = 3
description = "Remove qualquer imagem taggeada com mais de 1 dias (fallback de segurança)"
selection = {
tagStatus = "tagged"
countType = "sinceImagePushed"
countUnit = "days"
countNumber = 1
}
action = {
type = "expire"
}
}
]
})
Expand All @@ -96,29 +109,42 @@ resource "aws_ecr_lifecycle_policy" "builder_repository_policy" {
policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Manter apenas as últimas 1 imagens para otimizar custos"
rulePriority = 1
description = "Remove imagens não-taggeadas imediatamente (exceto a mais recente)"
selection = {
tagStatus = "untagged"
countType = "imageCountMoreThan"
countNumber = 1
tagStatus = "untagged"
countType = "imageCountMoreThan"
countNumber = 1
}
action = {
type = "expire"
}
},
{
rulePriority = 2
description = "Manter apenas as últimas 1 imagens taggeadas"
description = "Mantém apenas 1 imagem por tag específica - remove versões antigas"
selection = {
tagStatus = "tagged"
tagPrefixList = ["latest", "v", "dev", "prod", "staging"]
tagPrefixList = ["latest", "v", "dev", "prod", "staging", "main"]
countType = "imageCountMoreThan"
countNumber = 1
}
action = {
type = "expire"
}
},
{
rulePriority = 3
description = "Remove qualquer imagem taggeada com mais de 1 dias (fallback de segurança)"
selection = {
tagStatus = "tagged"
countType = "sinceImagePushed"
countUnit = "days"
countNumber = 1
}
action = {
type = "expire"
}
}
]
})
Expand All @@ -128,32 +154,45 @@ resource "aws_ecr_lifecycle_policy" "builder_repository_policy" {
resource "aws_ecr_lifecycle_policy" "notification_repository_policy" {
repository = aws_ecr_repository.notification_repository.name

policy = jsonencode({
policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Manter apenas as últimas 1 imagens para otimizar custos"
rulePriority = 1
description = "Remove imagens não-taggeadas imediatamente (exceto a mais recente)"
selection = {
tagStatus = "untagged"
countType = "imageCountMoreThan"
countNumber = 1
tagStatus = "untagged"
countType = "imageCountMoreThan"
countNumber = 1
}
action = {
type = "expire"
}
},
{
rulePriority = 2
description = "Manter apenas as últimas 1 imagens taggeadas"
description = "Mantém apenas 1 imagem por tag específica - remove versões antigas"
selection = {
tagStatus = "tagged"
tagPrefixList = ["latest", "v", "dev", "prod", "staging"]
tagPrefixList = ["latest", "v", "dev", "prod", "staging", "main"]
countType = "imageCountMoreThan"
countNumber = 1
}
action = {
type = "expire"
}
},
{
rulePriority = 3
description = "Remove qualquer imagem taggeada com mais de 1 dias (fallback de segurança)"
selection = {
tagStatus = "tagged"
countType = "sinceImagePushed"
countUnit = "days"
countNumber = 1
}
action = {
type = "expire"
}
}
]
})
Expand Down