@@ -4,7 +4,7 @@ resource "aws_eks_cluster" "this" {
4
4
version = " ${ var . cluster_version } "
5
5
6
6
vpc_config {
7
- security_group_ids = [" ${ aws_security_group . cluster . id } " ]
7
+ security_group_ids = [" ${ local . cluster_security_group_id } " ]
8
8
subnet_ids = [" ${ var . subnets } " ]
9
9
}
10
10
@@ -16,39 +16,43 @@ resource "aws_eks_cluster" "this" {
16
16
17
17
resource "aws_security_group" "cluster" {
18
18
name_prefix = " ${ var . cluster_name } "
19
- description = " Cluster communication with workers nodes "
19
+ description = " EKS cluster security group. "
20
20
vpc_id = " ${ var . vpc_id } "
21
21
tags = " ${ merge (var. tags , map (" Name" , " ${ var . cluster_name } -eks_cluster_sg" ))} "
22
+ count = " ${ var . cluster_security_group_id == " " ? 1 : 0 } "
22
23
}
23
24
24
25
resource "aws_security_group_rule" "cluster_egress_internet" {
25
- description = " Allow cluster egress to the Internet."
26
+ description = " Allow cluster egress access to the Internet."
26
27
protocol = " -1"
27
28
security_group_id = " ${ aws_security_group . cluster . id } "
28
29
cidr_blocks = [" 0.0.0.0/0" ]
29
30
from_port = 0
30
31
to_port = 0
31
32
type = " egress"
33
+ count = " ${ var . cluster_security_group_id == " " ? 1 : 0 } "
32
34
}
33
35
34
36
resource "aws_security_group_rule" "cluster_https_worker_ingress" {
35
- description = " Allow pods to communicate with the cluster API Server ."
37
+ description = " Allow pods to communicate with the EKS cluster API."
36
38
protocol = " tcp"
37
39
security_group_id = " ${ aws_security_group . cluster . id } "
38
- source_security_group_id = " ${ aws_security_group . workers . id } "
40
+ source_security_group_id = " ${ local . worker_security_group_id } "
39
41
from_port = 443
40
42
to_port = 443
41
43
type = " ingress"
44
+ count = " ${ var . cluster_security_group_id == " " ? 1 : 0 } "
42
45
}
43
46
44
47
resource "aws_security_group_rule" "cluster_https_cidr_ingress" {
45
- cidr_blocks = [" ${ var . cluster_ingress_cidrs } " ]
46
- description = " Allow communication with the cluster API Server ."
48
+ cidr_blocks = [" ${ local . workstation_external_cidr } " ]
49
+ description = " Allow kubectl communication with the EKS cluster API."
47
50
protocol = " tcp"
48
51
security_group_id = " ${ aws_security_group . cluster . id } "
49
52
from_port = 443
50
53
to_port = 443
51
54
type = " ingress"
55
+ count = " ${ var . cluster_security_group_id == " " ? 1 : 0 } "
52
56
}
53
57
54
58
resource "aws_iam_role" "cluster" {
0 commit comments