-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path35-worker-sg.tf
161 lines (136 loc) · 5.2 KB
/
35-worker-sg.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# worker sg
resource "aws_security_group" "worker" {
name = local.worker_name
description = "EKS worker node common security_group"
vpc_id = var.vpc_id
# egress {
# from_port = 0
# to_port = 0
# protocol = "-1"
# cidr_blocks = ["0.0.0.0/0"]
# ipv6_cidr_blocks = var.ip_family == "ipv6" ? ["::/0"] : null
# }
# revoke_rules_on_delete = true
tags = merge(
local.tags,
{
"Name" = local.worker_name
},
)
}
## worker ingress rules
resource "aws_security_group_rule" "worker_cluster" {
type = "ingress"
description = format("%s - cluster all", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = aws_security_group.cluster.id
}
resource "aws_security_group_rule" "worker_worker" {
type = "ingress"
description = format("%s - worker all", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = aws_security_group.worker.id
}
resource "aws_security_group_rule" "worker_source" {
count = length(var.worker_source_sgs)
type = "ingress"
description = format("%s - source all", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = var.worker_source_sgs[count.index]
}
resource "aws_security_group_rule" "worker_prefix_list" {
count = length(var.allow_prefix_list_ids)
type = "ingress"
description = format("%s - prefix_list", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
prefix_list_ids = [var.allow_prefix_list_ids[count.index]]
}
resource "aws_security_group_rule" "worker_ports_internal" {
count = length(var.worker_ports_internal)
type = "ingress"
description = format("%s - internal ports (%s)", local.worker_name, var.worker_ports_internal[count.index])
security_group_id = aws_security_group.worker.id
from_port = var.worker_ports_internal[count.index]
to_port = var.worker_ports_internal[count.index]
protocol = "TCP"
cidr_blocks = var.allow_cidr_internal
}
resource "aws_security_group_rule" "worker_ports_public" {
count = length(var.worker_ports_public)
type = "ingress"
description = format("%s - public ports (%s)", local.worker_name, var.worker_ports_public[count.index])
security_group_id = aws_security_group.worker.id
from_port = var.worker_ports_public[count.index]
to_port = var.worker_ports_public[count.index]
protocol = "TCP"
cidr_blocks = var.allow_cidr_public
}
## worker egress rules
resource "aws_security_group_rule" "worker_egress_22" {
type = "egress"
description = format("%s - egress 22", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 22
to_port = 22
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "worker_egress_80" {
type = "egress"
description = format("%s - egress 80", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 80
to_port = 80
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "worker_egress_443" {
type = "egress"
description = format("%s - egress 443", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "worker_egress_cluster" {
type = "egress"
description = format("%s - cluster all", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = aws_security_group.cluster.id
}
resource "aws_security_group_rule" "worker_egress_source" {
count = length(var.worker_source_sgs)
type = "egress"
description = format("%s - source all", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
source_security_group_id = var.worker_source_sgs[count.index]
}
resource "aws_security_group_rule" "worker_egress_prefix_list" {
count = length(var.allow_prefix_list_ids)
type = "egress"
description = format("%s - prefix_list", local.worker_name)
security_group_id = aws_security_group.worker.id
from_port = 0
to_port = 0
protocol = "-1"
prefix_list_ids = [var.allow_prefix_list_ids[count.index]]
}