-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam-role.tf
42 lines (35 loc) · 1.25 KB
/
iam-role.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
# Assume role policy for the default_ecs_role
data "aws_iam_policy_document" "default_ecs_role_assume_role_policy" {
count = length([
for provider in var.ec2_capacity_providers :
provider.instance_iam_role if provider.instance_iam_role == null
]) > 0 ? 1 : 0
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
# Default IAM role for the EC2 capacity providers
resource "aws_iam_role" "default_ecs_role" {
count = length([
for provider in var.ec2_capacity_providers :
provider.instance_iam_role if provider.instance_iam_role == null
]) > 0 ? 1 : 0
name = "${var.name}-default-ecs-role"
assume_role_policy = data.aws_iam_policy_document.default_ecs_role_assume_role_policy[0].json
tags = merge(
local.common_tags,
var.additional_tags_all
)
}
resource "aws_iam_role_policy_attachment" "default_ecs_role_policy_attachment" {
count = length([
for provider in var.ec2_capacity_providers :
provider.instance_iam_role if provider.instance_iam_role == null
]) > 0 ? 1 : 0
role = aws_iam_role.default_ecs_role[0].name
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}