-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.tf
46 lines (45 loc) · 1.21 KB
/
data.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
locals {
account-id = data.aws_caller_identity.current.account_id
}
# NOTE: this isn't really a public ECR repo; there's a condition
# only allows reads from an org, so this is a false positive
# in tfsec
# tfsec:ignore:aws-ecr-no-public-access
data "aws_iam_policy_document" "ecr_repo_policy" {
statement {
sid = "All Accounts in the Org can pull"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["*"]
}
actions = [
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:ListImages"
]
condition {
test = "StringEquals"
variable = "aws:PrincipalAccount"
values = ["${var.aws_account_id}"]
}
}
statement {
sid = "Allow push only from github actions"
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${local.account-id}:role/${var.iam_role}"]
}
actions = ["ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"]
condition {
test = "StringEquals"
variable = "aws:PrincipalAccount"
values = ["${var.aws_account_id}"]
}
}
}