Skip to content

Commit 70f3252

Browse files
authored
fix: Update the permission for the public ecr (#7)
1 parent be7fa43 commit 70f3252

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

main.tf

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ data "aws_iam_policy_document" "repository" {
2525
}
2626

2727
actions = [
28-
"ecr:BatchGetImage",
29-
"ecr:GetDownloadUrlForLayer",
28+
"ecr-public:BatchGetImage",
29+
"ecr-public:GetDownloadUrlForLayer",
3030
]
3131
}
3232
}
@@ -62,7 +62,7 @@ data "aws_iam_policy_document" "repository" {
6262
}
6363

6464
dynamic "statement" {
65-
for_each = length(var.repository_read_write_access_arns) > 0 ? [var.repository_read_write_access_arns] : []
65+
for_each = length(var.repository_read_write_access_arns) > 0 && var.repository_type == "private" ? [var.repository_read_write_access_arns] : []
6666

6767
content {
6868
sid = "ReadWrite"
@@ -80,6 +80,27 @@ data "aws_iam_policy_document" "repository" {
8080
]
8181
}
8282
}
83+
84+
dynamic "statement" {
85+
for_each = length(var.repository_read_write_access_arns) > 0 && var.repository_type == "public" ? [var.repository_read_write_access_arns] : []
86+
87+
content {
88+
sid = "ReadWrite"
89+
90+
principals {
91+
type = "AWS"
92+
identifiers = statement.value
93+
}
94+
95+
actions = [
96+
"ecr-public:BatchCheckLayerAvailability",
97+
"ecr-public:CompleteLayerUpload",
98+
"ecr-public:InitiateLayerUpload",
99+
"ecr-public:PutImage",
100+
"ecr-public:UploadLayerPart",
101+
]
102+
}
103+
}
83104
}
84105

85106
################################################################################

0 commit comments

Comments
 (0)