add firewall in terraform

This commit is contained in:
vincent 2022-06-19 19:04:15 +02:00
parent 59c3c79170
commit 7031c95a6c
2 changed files with 58 additions and 0 deletions

57
infra/firewall.tf Normal file
View File

@ -0,0 +1,57 @@
resource "hcloud_firewall" "HomeLab" {
name= "firewall-1"
rule {
direction ="in"
protocol = "tcp"
port = "80"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction ="in"
protocol = "tcp"
port = "443"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction ="in"
protocol = "tcp"
port = "6881"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction ="in"
protocol = "udp"
port = "51820"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction ="in"
protocol = "icmp"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
rule {
direction = "in"
protocol = "tcp"
port = "22"
source_ips = [
"0.0.0.0/0",
"::/0"
]
}
}

View File

@ -5,6 +5,7 @@ resource "hcloud_server" "HomeLab" {
server_type = var.server_type server_type = var.server_type
location = var.location location = var.location
ssh_keys = [hcloud_ssh_key.default.id] ssh_keys = [hcloud_ssh_key.default.id]
firewall_ids = [hcloud_firewall.HomeLab.id]
labels = { labels = {
} }