-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
93 lines (75 loc) · 2.02 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
data "aws_iam_policy_document" "traefik" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "ecs_role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "traefik" {
name = "traefik"
assume_role_policy = data.aws_iam_policy_document.traefik.json
}
data "aws_iam_policy_document" "traefik_policy" {
statement {
sid = "TraefikECSReadAccess"
effect = "Allow"
actions = [
"ecs:ListClusters",
"ecs:DescribeClusters",
"ecs:ListTasks",
"ecs:DescribeTasks",
"ecs:DescribeContainerInstances",
"ecs:DescribeTaskDefinition",
"ec2:DescribeInstances"
]
resources = [
"*",
]
}
}
data "aws_iam_policy_document" "traefik_data_policy" {
statement {
effect = "Allow"
actions = [
"ssm:GetParameters",
"secretsmanager:GetSecretValue",
"kms:Decrypt"
]
resources = [
var.aws_secret_access_key_arn
]
}
}
resource "aws_iam_role_policy" "traefik_policy" {
name = "traefik_policy"
role = aws_iam_role.traefik.id
policy = data.aws_iam_policy_document.traefik_policy.json
}
resource "aws_iam_role_policy" "traefik_data_policy" {
name = "traefik_data_policy"
role = aws_iam_role.traefik.id
policy = data.aws_iam_policy_document.traefik_data_policy.json
}
resource "aws_iam_role" "ecs_role" {
name = "ecs_role"
assume_role_policy = data.aws_iam_policy_document.ecs_role.json
}
resource "aws_iam_role_policy_attachment" "ecs_policy" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
role = aws_iam_role.ecs_role.name
}
resource "aws_iam_role_policy_attachment" "ecs_policy_secrets" {
policy_arn = "arn:aws:iam::aws:policy/SecretsManagerReadWrite"
role = aws_iam_role.ecs_role.name
}