-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path36-worker-iam.tf
119 lines (97 loc) · 2.56 KB
/
36-worker-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# worker iam
data "aws_iam_policy_document" "worker" {
statement {
effect = "Allow"
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com",
]
}
actions = [
"sts:AssumeRole"
]
}
}
resource "aws_iam_role" "worker" {
name = local.worker_name
assume_role_policy = data.aws_iam_policy_document.worker.json
tags = merge(
local.tags,
{
"Name" = local.worker_name
},
)
}
resource "aws_iam_instance_profile" "worker" {
name = local.worker_name
role = aws_iam_role.worker.name
tags = merge(
local.tags,
{
"Name" = local.worker_name
},
)
}
resource "aws_iam_role_policy_attachment" "worker_AmazonEKSWorkerNodePolicy" {
role = aws_iam_role.worker.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
}
resource "aws_iam_role_policy_attachment" "worker_AmazonEKS_CNI_Policy" {
role = aws_iam_role.worker.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
}
resource "aws_iam_role_policy_attachment" "worker_AmazonEC2ContainerRegistryReadOnly" {
role = aws_iam_role.worker.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
}
# worker_policies
resource "aws_iam_role_policy_attachment" "worker_policies" {
count = length(var.worker_policies)
role = aws_iam_role.worker.name
policy_arn = var.worker_policies[count.index]
}
# worker_ssm_access
data "aws_iam_policy" "worker_ssm_access" {
count = var.ssm_policy_name != "" ? 1 : 0
name = var.ssm_policy_name
}
resource "aws_iam_role_policy_attachment" "worker_ssm_access" {
count = var.ssm_policy_name != "" ? 1 : 0
role = aws_iam_role.worker.name
policy_arn = data.aws_iam_policy.worker_ssm_access.0.arn
}
# worker_additional_policies
resource "aws_iam_policy" "worker_additional_policies" {
name = format("%s-additional-policies", local.worker_name)
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ec2:AssignIpv6Addresses",
"ec2:CreateTags",
"ec2:DescribeInstances",
"ec2:DescribeInstanceTypes",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeTags",
"ssm:GetParameter"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
tags = merge(
local.tags,
{
"Name" = format("%s-additional-policies", local.worker_name)
},
)
}
resource "aws_iam_role_policy_attachment" "worker_additional_policies" {
role = aws_iam_role.worker.name
policy_arn = aws_iam_policy.worker_additional_policies.arn
}