-
Notifications
You must be signed in to change notification settings - Fork 1
/
security_groups.tf
87 lines (78 loc) · 3.07 KB
/
security_groups.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
/*
* Copyright (c) 2019 Netic A/S. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
resource "aws_security_group" "this" {
name = "eks-workers-${var.name}"
description = "Security Group for EKS worker nodes"
vpc_id = var.vpc_id
tags = merge(
{
"Name" = "eks-workers-${var.name}"
"kubernetes.io/cluster/${var.cluster_name}" = "owned"
},
var.tags,
local.tags,
)
lifecycle {
create_before_destroy = true
}
}
resource "aws_security_group_rule" "egress" {
description = "Allow all egress traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = join("", aws_security_group.this.*.id)
type = "egress"
}
resource "aws_security_group_rule" "ingress_self" {
description = "Allow nodes to communicate with each other"
from_port = 0
to_port = 65535
protocol = "-1"
security_group_id = join("", aws_security_group.this.*.id)
source_security_group_id = join("", aws_security_group.this.*.id)
type = "ingress"
}
resource "aws_security_group_rule" "ingress_cluster" {
description = "Allow worker kubelets and pods to receive communication from the cluster control plane"
from_port = 1025
to_port = 65535
protocol = "tcp"
security_group_id = join("", aws_security_group.this.*.id)
source_security_group_id = var.cluster_security_group_id
type = "ingress"
}
resource "aws_security_group_rule" "workers_ingress_cluster_https" {
description = "Allow pods running extension API servers on port 443 to receive communication from cluster control plane."
protocol = "tcp"
from_port = 443
to_port = 443
security_group_id = join("", aws_security_group.this.*.id)
source_security_group_id = var.cluster_security_group_id
type = "ingress"
}
resource "aws_security_group_rule" "ingress_security_groups" {
count = var.allowed_security_groups_count
description = "Allow inbound traffic from existing Security Groups"
from_port = 0
to_port = 65535
protocol = "-1"
security_group_id = join("", aws_security_group.this.*.id)
source_security_group_id = element(var.allowed_security_groups, count.index)
type = "ingress"
}
resource "aws_security_group_rule" "ingress_cidr_blocks" {
count = length(var.allowed_cidr_blocks) > 0 ? 1 : 0
description = "Allow inbound traffic from CIDR blocks"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = var.allowed_cidr_blocks
security_group_id = join("", aws_security_group.this.*.id)
type = "ingress"
}