forked from cloudposse/terraform-aws-ecs-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
47 lines (40 loc) · 1.13 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
locals {
policies_to_attach = toset([
"service-role/AmazonECSTaskExecutionRolePolicy",
"service-role/AmazonEC2ContainerServiceforEC2Role",
"AmazonSSMManagedInstanceCore"
])
}
resource "aws_iam_instance_profile" "default" {
count = local.enabled ? 1 : 0
name = module.this.id
role = module.this.id
}
data "aws_iam_policy_document" "assume" {
count = local.enabled ? 1 : 0
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["ec2.amazonaws.com"]
type = "Service"
}
effect = "Allow"
}
}
resource "aws_iam_role" "default" {
count = local.enabled ? 1 : 0
name = module.this.id
path = "/"
assume_role_policy = join("", data.aws_iam_policy_document.assume.*.json)
}
data "aws_partition" "current" {
count = local.enabled ? 1 : 0
}
resource "aws_iam_role_policy_attachment" "default" {
for_each = local.enabled ? local.policies_to_attach : []
role = join("", aws_iam_role.default.*.name)
policy_arn = format("arn:%s:iam::aws:policy/%s", join("", data.aws_partition.current.*.partition), each.value)
depends_on = [
aws_iam_role.default
]
}