Skip to content

Commit

Permalink
fix: Update the permission for the public ecr (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
niroz89 authored Jun 26, 2022
1 parent be7fa43 commit 70f3252
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ data "aws_iam_policy_document" "repository" {
}

actions = [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr-public:BatchGetImage",
"ecr-public:GetDownloadUrlForLayer",
]
}
}
Expand Down Expand Up @@ -62,7 +62,7 @@ data "aws_iam_policy_document" "repository" {
}

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

content {
sid = "ReadWrite"
Expand All @@ -80,6 +80,27 @@ data "aws_iam_policy_document" "repository" {
]
}
}

dynamic "statement" {
for_each = length(var.repository_read_write_access_arns) > 0 && var.repository_type == "public" ? [var.repository_read_write_access_arns] : []

content {
sid = "ReadWrite"

principals {
type = "AWS"
identifiers = statement.value
}

actions = [
"ecr-public:BatchCheckLayerAvailability",
"ecr-public:CompleteLayerUpload",
"ecr-public:InitiateLayerUpload",
"ecr-public:PutImage",
"ecr-public:UploadLayerPart",
]
}
}
}

################################################################################
Expand Down

0 comments on commit 70f3252

Please sign in to comment.