Skip to content

Commit 4fa00cd

Browse files
Merge pull request #52 from PythonFloripa/feature/ecr-lifecycle-policy-optimization
feat: otimiza política de ciclo de vida ECR para manter apenas 1 imag…
2 parents 2ef2a56 + 31e0aa3 commit 4fa00cd

File tree

1 file changed

+62
-23
lines changed

1 file changed

+62
-23
lines changed

terraform/modules/01.ecr/main.tf

Lines changed: 62 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,36 +55,49 @@ resource "aws_ecr_repository" "notification_repository" {
5555
}
5656

5757

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

6262
policy = jsonencode({
6363
rules = [
6464
{
65-
rulePriority = 1
66-
description = "Manter apenas as últimas 1 imagens para otimizar custos"
65+
rulePriority = 1
66+
description = "Remove imagens não-taggeadas imediatamente (exceto a mais recente)"
6767
selection = {
68-
tagStatus = "untagged"
69-
countType = "imageCountMoreThan"
70-
countNumber = 1
68+
tagStatus = "untagged"
69+
countType = "imageCountMoreThan"
70+
countNumber = 1
7171
}
7272
action = {
7373
type = "expire"
7474
}
7575
},
7676
{
7777
rulePriority = 2
78-
description = "Manter apenas as últimas 1 imagens taggeadas"
78+
description = "Mantém apenas 1 imagem por tag específica - remove versões antigas"
7979
selection = {
8080
tagStatus = "tagged"
81-
tagPrefixList = ["latest", "v", "dev", "prod", "staging"]
81+
tagPrefixList = ["latest", "v", "dev", "prod", "staging", "main"]
8282
countType = "imageCountMoreThan"
8383
countNumber = 1
8484
}
8585
action = {
8686
type = "expire"
8787
}
88+
},
89+
{
90+
rulePriority = 3
91+
description = "Remove qualquer imagem taggeada com mais de 1 dias (fallback de segurança)"
92+
selection = {
93+
tagStatus = "tagged"
94+
countType = "sinceImagePushed"
95+
countUnit = "days"
96+
countNumber = 1
97+
}
98+
action = {
99+
type = "expire"
100+
}
88101
}
89102
]
90103
})
@@ -96,29 +109,42 @@ resource "aws_ecr_lifecycle_policy" "builder_repository_policy" {
96109
policy = jsonencode({
97110
rules = [
98111
{
99-
rulePriority = 1
100-
description = "Manter apenas as últimas 1 imagens para otimizar custos"
112+
rulePriority = 1
113+
description = "Remove imagens não-taggeadas imediatamente (exceto a mais recente)"
101114
selection = {
102-
tagStatus = "untagged"
103-
countType = "imageCountMoreThan"
104-
countNumber = 1
115+
tagStatus = "untagged"
116+
countType = "imageCountMoreThan"
117+
countNumber = 1
105118
}
106119
action = {
107120
type = "expire"
108121
}
109122
},
110123
{
111124
rulePriority = 2
112-
description = "Manter apenas as últimas 1 imagens taggeadas"
125+
description = "Mantém apenas 1 imagem por tag específica - remove versões antigas"
113126
selection = {
114127
tagStatus = "tagged"
115-
tagPrefixList = ["latest", "v", "dev", "prod", "staging"]
128+
tagPrefixList = ["latest", "v", "dev", "prod", "staging", "main"]
116129
countType = "imageCountMoreThan"
117130
countNumber = 1
118131
}
119132
action = {
120133
type = "expire"
121134
}
135+
},
136+
{
137+
rulePriority = 3
138+
description = "Remove qualquer imagem taggeada com mais de 1 dias (fallback de segurança)"
139+
selection = {
140+
tagStatus = "tagged"
141+
countType = "sinceImagePushed"
142+
countUnit = "days"
143+
countNumber = 1
144+
}
145+
action = {
146+
type = "expire"
147+
}
122148
}
123149
]
124150
})
@@ -128,32 +154,45 @@ resource "aws_ecr_lifecycle_policy" "builder_repository_policy" {
128154
resource "aws_ecr_lifecycle_policy" "notification_repository_policy" {
129155
repository = aws_ecr_repository.notification_repository.name
130156

131-
policy = jsonencode({
157+
policy = jsonencode({
132158
rules = [
133159
{
134-
rulePriority = 1
135-
description = "Manter apenas as últimas 1 imagens para otimizar custos"
160+
rulePriority = 1
161+
description = "Remove imagens não-taggeadas imediatamente (exceto a mais recente)"
136162
selection = {
137-
tagStatus = "untagged"
138-
countType = "imageCountMoreThan"
139-
countNumber = 1
163+
tagStatus = "untagged"
164+
countType = "imageCountMoreThan"
165+
countNumber = 1
140166
}
141167
action = {
142168
type = "expire"
143169
}
144170
},
145171
{
146172
rulePriority = 2
147-
description = "Manter apenas as últimas 1 imagens taggeadas"
173+
description = "Mantém apenas 1 imagem por tag específica - remove versões antigas"
148174
selection = {
149175
tagStatus = "tagged"
150-
tagPrefixList = ["latest", "v", "dev", "prod", "staging"]
176+
tagPrefixList = ["latest", "v", "dev", "prod", "staging", "main"]
151177
countType = "imageCountMoreThan"
152178
countNumber = 1
153179
}
154180
action = {
155181
type = "expire"
156182
}
183+
},
184+
{
185+
rulePriority = 3
186+
description = "Remove qualquer imagem taggeada com mais de 1 dias (fallback de segurança)"
187+
selection = {
188+
tagStatus = "tagged"
189+
countType = "sinceImagePushed"
190+
countUnit = "days"
191+
countNumber = 1
192+
}
193+
action = {
194+
type = "expire"
195+
}
157196
}
158197
]
159198
})

0 commit comments

Comments
 (0)