-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheks.tf
83 lines (63 loc) · 2.29 KB
/
eks.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
resource "aws_eks_cluster" "main" {
name = "${var.project_name}-${var.environment}-cluster"
role_arn = aws_iam_role.clusterrole.arn
version = "1.30"
vpc_config {
subnet_ids = flatten([aws_subnet.publicsubnets[*].id, aws_subnet.privatesubnets[*].id])
endpoint_private_access = true
endpoint_public_access = true
public_access_cidrs = ["0.0.0.0/0"]
}
tags = merge(var.common_tags,
{
"Name" : "${var.project_name}-${var.environment}-cluster"
}
)
depends_on = [aws_iam_role_policy_attachment.cluster_role_policy_attachment]
}
resource "aws_iam_role" "clusterrole" {
name = "${var.project_name}-${var.environment}-eks-cluster-role"
assume_role_policy = data.aws_iam_policy_document.assume_role.json
tags = merge(var.common_tags,
{
"Name" : "${var.project_name}-${var.environment}-eks-cluster-role"
}
)
}
resource "aws_iam_role_policy_attachment" "cluster_role_policy_attachment" {
role = aws_iam_role.clusterrole.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}
resource "aws_eks_node_group" "main" {
cluster_name = aws_eks_cluster.main.name
node_group_name = "${var.project_name}-${var.environment}-cluster-node-group"
node_role_arn = aws_iam_role.workerrole.arn
depends_on = [aws_iam_role_policy_attachment.workerrole-policy-attachments]
subnet_ids = aws_subnet.privatesubnets[*].id
scaling_config {
desired_size = var.node_group_minsize
min_size = var.node_group_minsize
max_size = var.node_group_maxsize
}
update_config {
max_unavailable = 1
}
ami_type = "AL2_x86_64"
disk_size = "20"
capacity_type = "ON_DEMAND"
instance_types = [var.nodegroup_instance_type]
}
resource "aws_iam_role" "workerrole" {
name = "${var.project_name}-${var.environment}-eks-worker-role"
assume_role_policy = data.aws_iam_policy_document.assume_role_nodes.json
tags = merge(var.common_tags,
{
"Name" : "${var.project_name}-${var.environment}-eks-worker-role"
}
)
}
resource "aws_iam_role_policy_attachment" "workerrole-policy-attachments" {
count = length(var.workerrole_policy_arns)
policy_arn = element(var.workerrole_policy_arns, count.index)
role = aws_iam_role.workerrole.name
}