-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.tf
More file actions
70 lines (59 loc) · 1.99 KB
/
role.tf
File metadata and controls
70 lines (59 loc) · 1.99 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
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"]
}
}
}
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 managed node groups
resource "aws_iam_role" "node" {
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_worker" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node_cni" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node_ecr" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.node.name
}