-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecr.tf
61 lines (53 loc) · 1.72 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
# trivy:ignore:AVD-AWS-0033 - Repository is not encrypted using KMS
resource "aws_ecr_repository" "assets" {
name = local.has_custom_container_assets_repository_name == true ? var.container_assets_repository_name : "cdk-${var.qualifier}-container-assets-${data.aws_caller_identity.current.account_id}-${data.aws_region.current.name}"
image_tag_mutability = "IMMUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
resource "aws_ecr_lifecycle_policy" "assets" {
repository = aws_ecr_repository.assets.name
policy = <<EOF
{
"rules": [
{
"rulePriority": 1,
"description": "Untagged images should not exist, but expire any older than one year",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": ${local.expiration_window_in_days}
},
"action": {
"type": "expire"
}
}
]
}
EOF
}
data "aws_iam_policy_document" "container_assets" {
statement {
sid = "LambdaECRImageRetrievalPolicy"
effect = "Allow"
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
actions = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
]
condition {
test = "ArnLike"
variable = "aws:SourceArn"
values = ["arn:aws:lambda:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:function:*"]
}
}
}
resource "aws_ecr_repository_policy" "container_assets" {
repository = aws_ecr_repository.assets.name
policy = data.aws_iam_policy_document.container_assets.json
}