-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
95 lines (87 loc) · 1.96 KB
/
iam.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
resource "aws_iam_user" "publisher" {
count = local.addons.iam.enable ? 1 : 0
name = "ecr-publisher"
path = "/serviceaccounts/"
}
resource "aws_iam_role" "this" {
name = "fargate-role"
path = "/serviceaccounts/"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = [
"ecs.amazonaws.com",
"ecs-tasks.amazonaws.com"
]
}
},
]
})
}
resource "aws_iam_user_policy" "publisher" {
count = local.addons.iam.enable ? 1 : 0
name = "ecr-publisher"
user = aws_iam_user.publisher.0.name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"iam:PassRole",
"iam:GetRole",
"ecs:DescribeTaskDefinition",
"ecs:DescribeServices",
"ecs:UpdateService",
"ecs:RegisterTaskDefinition",
"ecr:CompleteLayerUpload",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:GetAuthorizationToken",
"ecr:GetDownloadUrlForLayer",
"ecr:GetLifecyclePolicy",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}
resource "aws_iam_access_key" "publisher" {
count = local.addons.iam.enable ? 1 : 0
user = aws_iam_user.publisher.0.name
}
resource "aws_iam_role_policy" "this" {
name = "fargate-execution-role"
role = aws_iam_role.this.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ecr:CompleteLayerUpload",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:GetAuthorizationToken",
"ecr:GetDownloadUrlForLayer",
"ecr:GetLifecyclePolicy"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}