2021-11-30 23:09:34 +01:00
|
|
|
resource "random_password" "k3s_token" {
|
2021-07-30 10:12:37 +02:00
|
|
|
length = 48
|
|
|
|
special = false
|
|
|
|
}
|
|
|
|
|
2022-02-05 00:02:25 +01:00
|
|
|
resource "hcloud_ssh_key" "k3s" {
|
|
|
|
name = "k3s"
|
2021-11-30 23:09:34 +01:00
|
|
|
public_key = local.ssh_public_key
|
2021-07-30 10:12:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "hcloud_network" "k3s" {
|
2022-02-05 00:02:25 +01:00
|
|
|
name = "k3s"
|
2021-07-30 10:12:37 +02:00
|
|
|
ip_range = "10.0.0.0/8"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "hcloud_network_subnet" "k3s" {
|
|
|
|
network_id = hcloud_network.k3s.id
|
|
|
|
type = "cloud"
|
2022-01-29 20:21:30 +01:00
|
|
|
network_zone = var.network_region
|
2021-07-30 10:12:37 +02:00
|
|
|
ip_range = "10.0.0.0/16"
|
|
|
|
}
|
|
|
|
|
2021-09-01 00:37:11 +02:00
|
|
|
resource "hcloud_firewall" "k3s" {
|
2022-02-05 00:02:25 +01:00
|
|
|
name = "k3s"
|
2021-09-01 00:37:11 +02:00
|
|
|
|
2021-12-10 00:48:45 +01:00
|
|
|
# Allowing internal cluster traffic and Hetzner metadata service and cloud API IPs
|
2021-09-01 00:37:11 +02:00
|
|
|
rule {
|
|
|
|
direction = "in"
|
|
|
|
protocol = "tcp"
|
|
|
|
port = "any"
|
|
|
|
source_ips = [
|
|
|
|
"127.0.0.1/32",
|
|
|
|
"10.0.0.0/8",
|
|
|
|
"169.254.169.254/32",
|
|
|
|
"213.239.246.1/32"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
direction = "in"
|
|
|
|
protocol = "udp"
|
|
|
|
port = "any"
|
|
|
|
source_ips = [
|
|
|
|
"127.0.0.1/32",
|
|
|
|
"10.0.0.0/8",
|
|
|
|
"169.254.169.254/32",
|
|
|
|
"213.239.246.1/32"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
direction = "in"
|
|
|
|
protocol = "icmp"
|
|
|
|
source_ips = [
|
|
|
|
"127.0.0.1/32",
|
|
|
|
"10.0.0.0/8",
|
|
|
|
"169.254.169.254/32",
|
|
|
|
"213.239.246.1/32"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow all traffic to the kube api server
|
|
|
|
rule {
|
|
|
|
direction = "in"
|
|
|
|
protocol = "tcp"
|
|
|
|
port = "6443"
|
|
|
|
source_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow all traffic to the ssh port
|
|
|
|
rule {
|
|
|
|
direction = "in"
|
|
|
|
protocol = "tcp"
|
|
|
|
port = "22"
|
|
|
|
source_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
2021-07-30 10:12:37 +02:00
|
|
|
|
2021-11-30 23:09:34 +01:00
|
|
|
# Allow ping on ipv4
|
|
|
|
rule {
|
|
|
|
direction = "in"
|
|
|
|
protocol = "icmp"
|
|
|
|
source_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
2021-07-30 10:12:37 +02:00
|
|
|
}
|
2022-01-05 15:04:22 +01:00
|
|
|
|
|
|
|
# Allow basic out traffic
|
|
|
|
# ICMP to ping outside services
|
|
|
|
rule {
|
|
|
|
direction = "out"
|
|
|
|
protocol = "icmp"
|
|
|
|
destination_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# DNS
|
|
|
|
rule {
|
|
|
|
direction = "out"
|
|
|
|
protocol = "tcp"
|
|
|
|
port = "53"
|
|
|
|
destination_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
direction = "out"
|
|
|
|
protocol = "udp"
|
|
|
|
port = "53"
|
|
|
|
destination_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# HTTP(s)
|
|
|
|
rule {
|
|
|
|
direction = "out"
|
|
|
|
protocol = "tcp"
|
|
|
|
port = "80"
|
|
|
|
destination_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
direction = "out"
|
|
|
|
protocol = "tcp"
|
|
|
|
port = "443"
|
|
|
|
destination_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
#NTP
|
|
|
|
rule {
|
|
|
|
direction = "out"
|
|
|
|
protocol = "udp"
|
|
|
|
port = "123"
|
|
|
|
destination_ips = [
|
|
|
|
"0.0.0.0/0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2021-07-30 10:12:37 +02:00
|
|
|
}
|
|
|
|
|
2022-01-13 13:32:17 +01:00
|
|
|
resource "local_file" "hetzner_ccm_config" {
|
|
|
|
content = templatefile("${path.module}/templates/hetzner_ccm.yaml.tpl", {
|
|
|
|
ccm_version = var.hetzner_ccm_version != null ? var.hetzner_ccm_version : data.github_release.hetzner_ccm.release_tag
|
2022-01-15 09:14:25 +01:00
|
|
|
patch_name = var.hetzner_ccm_containers_latest ? "patch_latest" : "patch"
|
2022-01-13 13:32:17 +01:00
|
|
|
})
|
|
|
|
filename = "${path.module}/hetzner/ccm/kustomization.yaml"
|
|
|
|
file_permission = "0644"
|
|
|
|
directory_permission = "0755"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "local_file" "hetzner_csi_config" {
|
|
|
|
content = templatefile("${path.module}/templates/hetzner_csi.yaml.tpl", {
|
|
|
|
csi_version = var.hetzner_csi_version != null ? var.hetzner_csi_version : data.github_release.hetzner_csi.release_tag
|
2022-01-15 09:14:25 +01:00
|
|
|
patch_name = var.hetzner_csi_containers_latest ? "patch_latest" : ""
|
2022-01-13 13:32:17 +01:00
|
|
|
})
|
|
|
|
filename = "${path.module}/hetzner/csi/kustomization.yaml"
|
|
|
|
file_permission = "0644"
|
|
|
|
directory_permission = "0755"
|
2021-09-01 00:37:11 +02:00
|
|
|
}
|
2022-01-05 15:04:22 +01:00
|
|
|
|
|
|
|
resource "local_file" "traefik_config" {
|
|
|
|
content = templatefile("${path.module}/templates/traefik_config.yaml.tpl", {
|
2022-02-01 23:32:10 +01:00
|
|
|
lb_disable_ipv6 = var.lb_disable_ipv6
|
|
|
|
lb_server_type = var.lb_server_type
|
|
|
|
location = var.location
|
|
|
|
traefik_acme_tls = var.traefik_acme_tls
|
|
|
|
traefik_acme_email = var.traefik_acme_email
|
2022-01-05 15:04:22 +01:00
|
|
|
})
|
2022-01-13 13:32:17 +01:00
|
|
|
filename = "${path.module}/templates/rendered/traefik_config.yaml"
|
|
|
|
file_permission = "0644"
|
|
|
|
directory_permission = "0755"
|
2022-01-05 15:04:22 +01:00
|
|
|
}
|
2022-01-29 21:15:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
resource "hcloud_placement_group" "k3s_placement_group" {
|
|
|
|
name = "k3s-placement-group"
|
|
|
|
type = "spread"
|
|
|
|
labels = {
|
|
|
|
"provisioner" = "terraform",
|
|
|
|
"engine" = "k3s"
|
|
|
|
}
|
|
|
|
}
|