-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecr.tf
64 lines (58 loc) · 1.57 KB
/
ecr.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
resource "aws_ecr_repository" "application" {
count = var.image == "" ? 1 : 0
name = local.name
image_scanning_configuration {
scan_on_push = var.image_scanning
}
tags = local.tags
}
resource "aws_ecr_lifecycle_policy" "application" {
count = var.image == "" ? 1 : 0
repository = aws_ecr_repository.application[0].name
policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Expire untagged images older than ${var.ecr_untagged_lifetime}"
selection = {
tagStatus = "untagged"
countType = "sinceImagePushed"
countUnit = "days"
countNumber = var.ecr_untagged_lifetime
}
action = {
type = "expire"
}
},
{
rulePriority = 2
description = "Keep important tags safe."
selection = {
tagStatus = "tagged"
tagPrefixList = var.ecr_tag_prefix_list
countType = "imageCountMoreThan"
countNumber = 10000
}
action = {
type = "expire"
}
},
{
rulePriority = 3
description = "Expire tagged images and keep last ${var.ecr_number_of_newest_tags}"
selection = {
tagStatus = "any"
countType = "imageCountMoreThan"
countNumber = var.ecr_number_of_newest_tags
}
action = {
type = "expire"
}
},
]
})
depends_on = [aws_ecr_repository.application]
}
output "ecr_repository" {
value = aws_ecr_repository.application[0].repository_url
}