-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
61 lines (49 loc) · 1.64 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
resource "aws_iam_role" "ecs_task_execution" {
name = "${var.name}-ecs_task_execution"
assume_role_policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "ecs_task_execution" {
count = "${length(var.policies_arn)}"
role = "${aws_iam_role.ecs_task_execution.id}"
policy_arn = "${element(var.policies_arn, count.index)}"
}
data "aws_iam_policy_document" "ecs_task_access_secrets" {
statement {
effect = "Allow"
resources = [
"arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${var.webhook_ssm_parameter_name}",
"arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${var.atlantis_github_user_token_ssm_parameter_name}",
]
actions = [
"ssm:GetParameters",
"secretsmanager:GetSecretValue",
]
}
}
data "aws_iam_policy_document" "ecs_task_access_secrets_with_kms" {
source_json = "${data.aws_iam_policy_document.ecs_task_access_secrets.0.json}"
statement {
sid = "AllowKMSDecrypt"
effect = "Allow"
actions = ["kms:Decrypt"]
resources = [ "*" ]
}
}
resource "aws_iam_role_policy" "ecs_task_access_secrets" {
name = "ECSTaskAccessSecretsPolicy"
role = "${aws_iam_role.ecs_task_execution.id}"
policy = "${element(compact(concat(data.aws_iam_policy_document.ecs_task_access_secrets_with_kms.*.json, data.aws_iam_policy_document.ecs_task_access_secrets.*.json)), 0)}"
}