-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
44 lines (38 loc) · 1.02 KB
/
main.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
resource "aws_ecr_repository" "repo" {
name = local.name
image_tag_mutability = var.image_tag_mutability
force_delete = var.force_delete
image_scanning_configuration {
scan_on_push = var.scan_on_push
}
encryption_configuration {
encryption_type = var.encryption_configuration["encryption_type"]
kms_key = var.encryption_configuration["kms_key_arn"]
}
tags = local.tags
}
resource "aws_ecr_lifecycle_policy" "repo_lifecycle_policy" {
count = var.images_to_retain == null ? 0 : 1
repository = local.name
policy = <<EOF
{
"rules": [
{
"rulePriority": 1,
"description": "Keep last ${var.images_to_retain} images",
"selection": {
"tagStatus": "any",
"countType": "imageCountMoreThan",
"countNumber": ${var.images_to_retain}
},
"action": {
"type": "expire"
}
}
]
}
EOF
depends_on = [
aws_ecr_repository.repo,
]
}