forked from reireias/rails-on-ecs-terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam_user_actions.tf
92 lines (83 loc) · 2.23 KB
/
iam_user_actions.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
# NOTE: IAM User for Image Build and Deploy on GitHub Actions.
resource "aws_iam_user" "actions" {
name = "${local.name}-actions"
}
resource "aws_iam_access_key" "actions" {
user = aws_iam_user.actions.name
}
resource "aws_iam_policy" "actions" {
name = "${local.name}-actions"
policy = data.aws_iam_policy_document.actions.json
}
data "aws_iam_policy_document" "actions" {
statement {
sid = "ECRPushPullPolicy"
actions = [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"ecr:PutImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
]
resources = [
aws_ecr_repository.rails.arn,
]
}
statement {
sid = "ECRAuthPolicy"
actions = [
"ecr:GetAuthorizationToken",
]
resources = ["*"]
}
statement {
sid = "GetBuildObject"
actions = [
"s3:GetObject",
]
resources = [
"${aws_s3_bucket.build.arn}/*",
]
}
# see: https://github.com/aws-actions/amazon-ecs-deploy-task-definition#aws-codedeploy-support
statement {
sid = "RegisterTaskDefinition"
actions = [
"ecs:RegisterTaskDefinition",
]
resources = ["*"]
}
statement {
sid = "PassRolesInTaskDefinition"
actions = [
"iam:PassRole",
]
resources = [
aws_iam_role.ecs.arn,
aws_iam_role.ecs_task.arn,
]
}
statement {
sid = "DeployService"
actions = [
"ecs:DescribeServices",
"codedeploy:GetDeploymentGroup",
"codedeploy:CreateDeployment",
"codedeploy:GetDeployment",
"codedeploy:GetDeploymentConfig",
"codedeploy:RegisterApplicationRevision",
]
resources = [
aws_ecs_service.app.id,
"arn:aws:codedeploy:${local.region}:${local.account_id}:application:${aws_codedeploy_app.app.name}",
"arn:aws:codedeploy:${local.region}:${local.account_id}:deploymentgroup:${aws_codedeploy_app.app.name}/${aws_codedeploy_deployment_group.app.deployment_group_name}",
"arn:aws:codedeploy:${local.region}:${local.account_id}:deploymentconfig:*",
]
}
}
resource "aws_iam_user_policy_attachment" "actions" {
user = aws_iam_user.actions.name
policy_arn = aws_iam_policy.actions.arn
}