-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsg-node.tf
54 lines (50 loc) · 1.7 KB
/
sg-node.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
variable "public_ports" {
description = "List of publicly open ports"
type = list(number)
default = [
1800, # Stratum Server
8114, # CKB RPC
8115, # CKB p2p
9021, # Kafka control center
9090, # Prometheus
3000, # Grafana
]
}
resource "alicloud_security_group" "node-sg" {
name = var.node_sg_name
vpc_id = alicloud_vpc.vpc.id
description = "Security group for node traffic"
}
resource "alicloud_security_group_rule" "node-ssh-in" {
count = ! var.bastion_enabled ? 1 : 0
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "22/22"
priority = 1
security_group_id = alicloud_security_group.node-sg.id
cidr_ip = "0.0.0.0/0"
}
resource "alicloud_security_group_rule" "node-bastion-in" {
count = var.bastion_enabled ? 1 : 0
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "22/22"
priority = 1
security_group_id = alicloud_security_group.node-sg.id
source_security_group_id = coalesce(join(",", alicloud_security_group.bastion-sg.*.id))
}
resource "alicloud_security_group_rule" "node-app-in" {
count = length(var.public_ports)
type = "ingress"
ip_protocol = "tcp"
nic_type = "intranet"
policy = "accept"
port_range = "${var.public_ports[count.index]}/${var.public_ports[count.index]}"
priority = 1
security_group_id = alicloud_security_group.node-sg.id
cidr_ip = "0.0.0.0/0"
}