Skip to content

Instantly share code, notes, and snippets.

@mmiranda
Created June 17, 2022 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmiranda/2617657b404fbf230497196fc1c99c5a to your computer and use it in GitHub Desktop.
Save mmiranda/2617657b404fbf230497196fc1c99c5a to your computer and use it in GitHub Desktop.
ECR Access from differents organizations
// 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