-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.tf
More file actions
97 lines (83 loc) · 3.04 KB
/
role.tf
File metadata and controls
97 lines (83 loc) · 3.04 KB
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
resource "aws_iam_role" "this" {
name = local.resource_name
assume_role_policy = data.aws_iam_policy_document.this_assume.json
tags = local.tags
}
data "aws_iam_policy_document" "this_assume" {
statement {
sid = "AssumeEKS"
effect = "Allow"
actions = ["sts:AssumeRole", "sts:TagSession"]
principals {
type = "Service"
identifiers = [
"eks.amazonaws.com",
"eks-fargate-pods.amazonaws.com",
]
}
}
}
resource "aws_iam_role_policy_attachment" "this_basic" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this_service" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
role = aws_iam_role.this.name
}
# Enable Security Groups for Pods
# Reference: https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html
resource "aws_iam_role_policy_attachment" "this_vpc" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
role = aws_iam_role.this.name
}
# Node IAM role for EKS Auto Mode
resource "aws_iam_role" "node" {
count = var.enable_auto_mode ? 1 : 0
name = "${local.resource_name}-node"
assume_role_policy = data.aws_iam_policy_document.node_assume.json
tags = local.tags
}
data "aws_iam_policy_document" "node_assume" {
statement {
sid = "AssumeEC2"
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy_attachment" "node_minimal" {
count = var.enable_auto_mode ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodeMinimalPolicy"
role = aws_iam_role.node[0].name
}
resource "aws_iam_role_policy_attachment" "node_ecr" {
count = var.enable_auto_mode ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPullOnly"
role = aws_iam_role.node[0].name
}
# Required managed policies for EKS Auto Mode on the cluster role
# Reference: https://docs.aws.amazon.com/eks/latest/userguide/auto-cluster-iam-role.html
resource "aws_iam_role_policy_attachment" "this_eks_block_storage" {
count = var.enable_auto_mode ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSBlockStoragePolicy"
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this_eks_compute" {
count = var.enable_auto_mode ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSComputePolicy"
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this_eks_load_balancing" {
count = var.enable_auto_mode ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSLoadBalancingPolicy"
role = aws_iam_role.this.name
}
resource "aws_iam_role_policy_attachment" "this_eks_networking" {
count = var.enable_auto_mode ? 1 : 0
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSNetworkingPolicy"
role = aws_iam_role.this.name
}