This repository has been archived by the owner on Apr 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cluster.tf
92 lines (77 loc) · 2.85 KB
/
cluster.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
83
84
85
86
87
88
89
90
91
92
resource "aws_eks_cluster" "this" {
name = var.cluster_name
version = var.cluster_version
role_arn = aws_iam_role.cluster.arn
vpc_config {
security_group_ids = [aws_security_group.cluster.id]
subnet_ids = var.private_subnets
endpoint_private_access = var.cluster_endpoint_private_access
endpoint_public_access = var.cluster_endpoint_public_access
}
enabled_cluster_log_types = var.enabled_cluster_log_types
depends_on = [
aws_iam_role_policy_attachment.cluster_AmazonEKSClusterPolicy,
aws_iam_role_policy_attachment.cluster_AmazonEKSServicePolicy,
]
}
data "aws_iam_policy_document" "cluster" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["eks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "cluster" {
name = "${var.cluster_name}-cluster"
assume_role_policy = data.aws_iam_policy_document.cluster.json
force_detach_policies = true
}
resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSClusterPolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.cluster.name
}
resource "aws_iam_role_policy_attachment" "cluster_AmazonEKSServicePolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
role = aws_iam_role.cluster.name
}
resource "aws_security_group" "cluster" {
name = "${var.cluster_name}-cluster"
description = "EKS Cluster ENI"
vpc_id = var.vpc_id
}
resource "aws_security_group_rule" "worker_to_master" {
security_group_id = aws_security_group.cluster.id
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
source_security_group_id = aws_security_group.workers.id
}
resource "aws_security_group_rule" "master_to_worker" {
security_group_id = aws_security_group.cluster.id
type = "egress"
from_port = 0
to_port = 65535
protocol = "tcp"
source_security_group_id = aws_security_group.workers.id
}
resource "aws_security_group_rule" "additional_sg_ingress" {
count = length(var.cluster_access_additional_sg)
security_group_id = aws_security_group.cluster.id
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
source_security_group_id = var.cluster_access_additional_sg[count.index]
}
resource "aws_security_group_rule" "additional_ip_ingress" {
count = length(var.cluster_access_additional_ip) > 0 ? 1 : 0
security_group_id = aws_security_group.cluster.id
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = var.cluster_access_additional_ip
}