-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathecr.tf
55 lines (51 loc) · 1.27 KB
/
ecr.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
data "aws_iam_policy_document" "assume_by_ecr" {
statement {
sid = ""
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["codebuild.amazonaws.com"]
}
}
}
resource "aws_iam_role" "ecr" {
name = "${var.service_name}-ECR-ReadForECSServiceAccount"
assume_role_policy = "${data.aws_iam_policy_document.assume_by_ecr.json}"
}
resource "aws_ecr_repository" "this" {
name = "${var.service_name}"
}
resource "aws_ecr_repository_policy" "this" {
repository = "${var.service_name}"
policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "${var.service_name}",
"Effect": "Allow",
"Principal": {
"AWS": [
"${aws_iam_role.ecr.arn}",
"${aws_iam_role.codebuild.arn}",
"${aws_iam_role.codedeploy.arn}",
"${aws_iam_role.pipeline.arn}"
]
},
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:GetRepositoryPolicy",
"ecr:ListImages"
]
}
]
}
EOF
}