Skip to content

Commit 9dd70b9

Browse files
authored
Merge pull request #20 from otuma-skippay/feature/ecr-lifecycle-policy
Feature/ecr lifecycle policy
2 parents b34d557 + 4b3370f commit 9dd70b9

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The service is behind a load balancer which means it is exposed. A HTTP healthch
5050
| cooldown | n/a | `number` | `60` | no |
5151
| cpu | CPU reservation for the task | `number` | `256` | no |
5252
| deregistration\_delay | n/a | `number` | `30` | no |
53-
| ecr\_tag\_prefix\_list | n/a | `list` | `["!latest"]` | no |
53+
| ecr\_tag\_prefix\_list | n/a | `list` | `["latest"]` | no |
5454
| ecr_number\_of\_newest_tags | n/a | `number` | `90` | no |
5555
| ecr\_untagged\_lifetime | n/a | `number` | `1` | no |
5656
| environment | n/a | `list` | `[]` | no |

ecr.tf

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resource "aws_ecr_repository" "application" {
1010
}
1111

1212
resource "aws_ecr_lifecycle_policy" "application" {
13-
count = var.image == "" ? 1 : 0
13+
count = var.image == "" ? 1 : 0
1414
repository = aws_ecr_repository.application[0].name
1515

1616
policy = jsonencode({
@@ -30,12 +30,24 @@ resource "aws_ecr_lifecycle_policy" "application" {
3030
},
3131
{
3232
rulePriority = 2
33-
description = "Expire tagged images and keep last ${var.ecr_number_of_newest_tags}"
33+
description = "Keep important tags safe."
3434
selection = {
3535
tagStatus = "tagged"
3636
tagPrefixList = var.ecr_tag_prefix_list
37-
countType = "imageCountMoreThan"
38-
countNumber = var.ecr_number_of_newest_tags
37+
countType = "imageCountMoreThan"
38+
countNumber = 10000
39+
}
40+
action = {
41+
type = "expire"
42+
}
43+
},
44+
{
45+
rulePriority = 3
46+
description = "Expire tagged images and keep last ${var.ecr_number_of_newest_tags}"
47+
selection = {
48+
tagStatus = "tagged"
49+
countType = "imageCountMoreThan"
50+
countNumber = var.ecr_number_of_newest_tags
3951
}
4052
action = {
4153
type = "expire"
@@ -44,7 +56,7 @@ resource "aws_ecr_lifecycle_policy" "application" {
4456
]
4557
})
4658

47-
depends_on = [ aws_ecr_repository.application ]
59+
depends_on = [aws_ecr_repository.application]
4860
}
4961

5062
output "ecr_repository" {

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,6 @@ variable "ecr_number_of_newest_tags" {
309309
}
310310

311311
variable "ecr_tag_prefix_list" {
312-
default = ["!latest"]
312+
default = ["latest"]
313313
type = list(string)
314314
}

0 commit comments

Comments
 (0)