forked from voyagegroup/tf_aws_ecs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiam.tf
40 lines (32 loc) · 904 Bytes
/
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
resource "aws_iam_role" "ecs_instance" {
name = "${aws_ecs_cluster.main.name}-ecs-instance-role"
path = var.iam_path
force_detach_policies = true
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "ecs_instance_policy" {
count = length(var.iam_policy_arns)
role = aws_iam_role.ecs_instance.name
policy_arn = element(var.iam_policy_arns, count.index)
depends_on = [aws_iam_role.ecs_instance]
}
resource "aws_iam_instance_profile" "ecs_instance" {
name = "${aws_ecs_cluster.main.name}-ecs-instance-profile"
role = aws_iam_role.ecs_instance.name
path = var.iam_path
depends_on = [aws_iam_role.ecs_instance]
}