-
Notifications
You must be signed in to change notification settings - Fork 45
/
iam_nodes.tf
95 lines (70 loc) · 2.16 KB
/
iam_nodes.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
data "aws_iam_policy_document" "eks_nodes_role" {
version = "2012-10-17"
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"ec2.amazonaws.com"
]
}
}
}
resource "aws_iam_role" "eks_nodes_roles" {
name = format("%s-eks-nodes", var.cluster_name)
assume_role_policy = data.aws_iam_policy_document.eks_nodes_role.json
}
resource "aws_iam_role_policy_attachment" "cni" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.eks_nodes_roles.name
}
resource "aws_iam_role_policy_attachment" "node" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.eks_nodes_roles.name
}
resource "aws_iam_role_policy_attachment" "ecr" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.eks_nodes_roles.name
}
resource "aws_iam_role_policy_attachment" "ssm" {
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
role = aws_iam_role.eks_nodes_roles.name
}
resource "aws_iam_role_policy_attachment" "cloudwatch" {
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
role = aws_iam_role.eks_nodes_roles.name
}
data "aws_iam_policy_document" "csi_driver" {
version = "2012-10-17"
statement {
effect = "Allow"
actions = [
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant",
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
]
resources = [
aws_kms_key.eks.arn
]
}
}
resource "aws_iam_policy" "csi_driver" {
name = format("%s-csi-driver", var.cluster_name)
path = "/"
description = var.cluster_name
policy = data.aws_iam_policy_document.csi_driver.json
}
resource "aws_iam_policy_attachment" "csi_driver" {
name = "aws_load_balancer_controller_policy"
roles = [aws_iam_role.eks_nodes_roles.name]
policy_arn = aws_iam_policy.csi_driver.arn
}
resource "aws_iam_instance_profile" "nodes" {
name = "${var.cluster_name}-instance-profile"
role = aws_iam_role.eks_nodes_roles.name
}