-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
127 lines (112 loc) · 3.24 KB
/
main.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
resource "hcloud_ssh_key" "default" {
name = "SSH_KEY"
public_key = var.SSH_KEY
}
resource "hcloud_network" "k3s_internal" {
ip_range = "10.0.0.0/24"
name = "k3s-internal"
}
resource "hcloud_network_subnet" "k3s_internal_subnet" {
type = "cloud"
network_zone = "eu-central"
ip_range = "10.0.0.0/24"
network_id = hcloud_network.k3s_internal.id
}
resource "hcloud_load_balancer" "entry_loadbalancer" {
name = "entry_loadbalancer"
load_balancer_type = "lb11"
network_zone = "eu-central"
algorithm {
type = "round_robin"
}
}
resource "hcloud_load_balancer_target" "entry_loadbalancer_targets" {
for_each = { for k, instance in hcloud_server.nodes[*] : k => instance }
type = "server"
load_balancer_id = hcloud_load_balancer.entry_loadbalancer.id
server_id = each.value.id
use_private_ip = true
}
resource "hcloud_load_balancer_network" "entry_loadbalancer_network" {
load_balancer_id = hcloud_load_balancer.entry_loadbalancer.id
network_id = hcloud_network.k3s_internal.id
ip = "10.0.0.254"
}
resource "hcloud_managed_certificate" "wildcard_cert" {
name = "wildcard_cert"
domain_names = ["*.kappes.space", "kappes.space"]
}
resource "hcloud_load_balancer_service" "entry_loadbalancer_service" {
load_balancer_id = hcloud_load_balancer.entry_loadbalancer.id
protocol = "https"
listen_port = "443"
destination_port = "80"
proxyprotocol = true
http {
sticky_sessions = true
certificates = [hcloud_managed_certificate.wildcard_cert.id]
redirect_http = true
}
health_check {
protocol = "http"
port = "443"
interval = "10"
timeout = "10"
http {
domain = "kappes.space"
path = "/"
status_codes = ["2??", "3??"]
tls = true
}
}
}
resource "hcloud_placement_group" "placement_group_master" {
name = "placement_group_master"
type = "spread"
}
resource "hcloud_placement_group" "placement_group_nodes" {
name = "placement_group_nodes"
type = "spread"
}
resource "hcloud_server" "masters" {
count = 3
name = "k3s-master-${count.index + 1}"
server_type = "cx11"
image = "debian-12"
ssh_keys = ["SSH_KEY"]
location = "fsn1"
placement_group_id = hcloud_placement_group.placement_group_master.id
labels = {
type = "master"
}
public_net {
ipv4_enabled = true
ipv6_enabled = false
}
network {
network_id = hcloud_network.k3s_internal.id
ip = "10.0.0.1${count.index + 1}"
}
depends_on = [hcloud_network_subnet.k3s_internal_subnet]
}
resource "hcloud_server" "nodes" {
count = 2
name = "k3s-node-${count.index + 1}"
server_type = "cx11"
image = "debian-12"
ssh_keys = ["SSH_KEY"]
location = "fsn1"
placement_group_id = hcloud_placement_group.placement_group_nodes.id
labels = {
type = "node"
}
public_net {
ipv4_enabled = true
ipv6_enabled = false
}
network {
network_id = hcloud_network.k3s_internal.id
ip = "10.0.0.2${count.index + 1}"
}
depends_on = [hcloud_network_subnet.k3s_internal_subnet]
}