Created
June 17, 2022 08:57
-
-
Save mmiranda/2617657b404fbf230497196fc1c99c5a to your computer and use it in GitHub Desktop.
ECR Access from differents organizations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Grant Read Only access to all account inside AWS organization | |
data "aws_iam_policy_document" "ecr_organization_readonly_access" { | |
statement { | |
sid = "ReadonlyAccess" | |
effect = "Allow" | |
principals { | |
type = "*" | |
identifiers = ["*"] | |
} | |
condition { | |
test = "StringLike" | |
variable = "aws:PrincipalOrgID" | |
values = [ | |
"o-123456", # Main Organization | |
"o-329873", # Different Organization | |
"o-sdf65s", # Another Organization | |
] | |
} | |
actions = [ | |
"ecr:GetAuthorizationToken", | |
"ecr:BatchCheckLayerAvailability", | |
"ecr:GetDownloadUrlForLayer", | |
"ecr:GetRepositoryPolicy", | |
"ecr:DescribeRepositories", | |
"ecr:ListImages", | |
"ecr:DescribeImages", | |
"ecr:BatchGetImage", | |
"ecr:DescribeImageScanFindings", | |
] | |
} | |
} | |
resource "aws_ecr_repository_policy" "ecr-policy" { | |
repository = "my-repo-name" | |
policy = data.aws_iam_policy_document.ecr_organization_readonly_access.json | |
depends_on = [ | |
aws_ecr_repository.my-repo-name | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment