-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheks.tf
More file actions
70 lines (59 loc) · 1.83 KB
/
eks.tf
File metadata and controls
70 lines (59 loc) · 1.83 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_eks_cluster" "eks_cluster" {
name = var.cluster_name
role_arn = aws_iam_role.eks_role.arn
version = "1.31"
vpc_config {
subnet_ids = aws_subnet.worker_subnets[*].id
}
depends_on = [aws_iam_role_policy_attachment.eks_cluster_attach]
}
resource "aws_iam_role" "eks_role" {
name = "eks-cluster-role"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Effect = "Allow",
Principal = { Service = "eks.amazonaws.com" },
Action = "sts:AssumeRole"
}]
})
}
resource "aws_iam_role_policy_attachment" "eks_cluster_attach" {
role = aws_iam_role.eks_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
}
resource "aws_eks_node_group" "eks_nodes" {
cluster_name = aws_eks_cluster.eks_cluster.name
node_group_name = var.nodegroup_name
node_role_arn = aws_iam_role.node_role.arn
instance_types = ["t3.medium"]
scaling_config {
desired_size = 2
min_size = 2
max_size = 5
}
subnet_ids = aws_subnet.worker_subnets[*].id
}
resource "aws_iam_role" "node_role" {
name = "eks-node-role"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Effect = "Allow",
Principal = { Service = "ec2.amazonaws.com" },
Action = "sts:AssumeRole"
}]
})
}
resource "aws_iam_role_policy_attachment" "node_role_attach" {
role = aws_iam_role.node_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
}
resource "aws_iam_role_policy_attachment" "node_cni_attach" {
role = aws_iam_role.node_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
}
resource "aws_iam_role_policy_attachment" "node_ec2_attach" {
role = aws_iam_role.node_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
}