Created
July 23, 2020 08:26
-
-
Save jufemaiz/4b8810483fe59ab190782af6fa9eed36 to your computer and use it in GitHub Desktop.
Basic terraform for remote account ECR access by an ECS
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
resource "aws_ecr_repository" "account_a" { | |
name = var.ecr_name | |
tags = local.tags | |
} | |
resource "aws_ecr_repository_policy" "account_a" { | |
repository = aws_ecr_repository.this.name | |
policy = data.aws_iam_policy_document.account_a.json | |
} | |
data "aws_iam_policy_document" "account_a" { | |
statement { | |
sid = "RemoteAccessPolicyDocument" | |
actions = [ | |
"ecr:GetAuthorizationToken", | |
"ecr:BatchCheckLayerAvailability", | |
"ecr:GetDownloadUrlForLayer", | |
"ecr:GetRepositoryPolicy", | |
"ecr:DescribeRepositories", | |
"ecr:ListImages", | |
"ecr:DescribeImages", | |
"ecr:BatchGetImage", | |
] | |
effect = "Allow" | |
principals { | |
type = "AWS" | |
identifiers = [ | |
"arn:aws:iam::${var.account_b_id}:root" | |
] | |
} | |
} | |
} |
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
data "aws_iam_policy_document" "execution" { | |
statement { | |
sid = "AllowECRAuth" | |
actions = [ | |
"ecr:GetAuthorizationToken", | |
] | |
resources = [ | |
"*" | |
] | |
} | |
statement { | |
sid = "AllowECRAccess" | |
actions = [ | |
"ecr:BatchCheckLayerAvailability", | |
"ecr:GetDownloadUrlForLayer", | |
"ecr:BatchGetImage", | |
] | |
resources = [ | |
var.account_a_ecr_arn | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment