This repository was archived by the owner on Oct 29, 2022. It is now read-only.
forked from opszero/terraform-aws-kubespot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_role.tf
More file actions
87 lines (73 loc) · 2.17 KB
/
Copy pathnode_role.tf
File metadata and controls
87 lines (73 loc) · 2.17 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
resource "aws_iam_role" "node" {
name = "${var.environment_name}-node"
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
Version = "2012-10-17"
})
tags = {
"KubespotEnvironment" = var.environment_name
}
}
output "node_role" {
value = aws_iam_role.node
}
resource "aws_iam_role_policy_attachment" "node-AmazonEKSWorkerNodePolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node-AmazonEKS_CNI_Policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "node-AmazonEC2ContainerRegistryReadOnly" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.node.name
}
resource "aws_iam_role_policy_attachment" "aws_node_oidc" {
role = aws_iam_role.node_oidc.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
}
resource "aws_iam_role_policy_attachment" "node_role_policies" {
count = length(var.node_role_policies)
policy_arn = var.node_role_policies[count.index]
role = aws_iam_role.node.name
}
resource "aws_iam_instance_profile" "node" {
name = "${var.environment_name}-node"
role = aws_iam_role.node.name
tags = {
"KubespotEnvironment" = var.environment_name
}
}
resource "aws_iam_role" "node_oidc" {
name = "${var.environment_name}-node-oidc"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "${aws_iam_openid_connect_provider.cluster.arn}"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"${replace(aws_iam_openid_connect_provider.cluster.url, "https://", "")}:sub": "system:serviceaccount:kube-system:cluster-autoscaler"
}
}
}
]
}
EOF
depends_on = [aws_iam_openid_connect_provider.cluster]
tags = {
"KubespotEnvironment" = var.environment_name
}
}