Skip to content

Commit 210ee09

Browse files
committed
feat(hetzner-cloud): add config and format module
1 parent 8a051bb commit 210ee09

File tree

2 files changed

+151
-52
lines changed

2 files changed

+151
-52
lines changed

registry/melmathari/templates/hetzner-cloud/hetzner-config.json

Lines changed: 139 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,58 @@
66
"nbg1": { "name": "Nuremberg, Germany", "zone": "eu-central" },
77
"hel1": { "name": "Helsinki, Finland", "zone": "eu-central" },
88
"ash": { "name": "Ashburn, VA, USA", "zone": "us-east" },
9-
"hil": { "name": "Hillsboro, OR, USA", "zone": "us-west" }
9+
"hil": { "name": "Hillsboro, OR, USA", "zone": "us-west" },
10+
"sin": { "name": "Singapore", "zone": "ap-southeast" }
1011
},
1112
"server_types": {
12-
"cx11": { "name": "CX11 (1 vCPU, 4 GB RAM)", "vcpus": 1, "memory": 4 },
13-
"cx21": { "name": "CX21 (2 vCPU, 8 GB RAM)", "vcpus": 2, "memory": 8 },
13+
"cax11": {
14+
"name": "CAX11 (2 vCPU, 4 GB RAM, ARM)",
15+
"vcpus": 2,
16+
"memory": 4
17+
},
18+
"cax21": {
19+
"name": "CAX21 (4 vCPU, 8 GB RAM, ARM)",
20+
"vcpus": 4,
21+
"memory": 8
22+
},
23+
"cax31": {
24+
"name": "CAX31 (8 vCPU, 16 GB RAM, ARM)",
25+
"vcpus": 8,
26+
"memory": 16
27+
},
28+
"cax41": {
29+
"name": "CAX41 (16 vCPU, 32 GB RAM, ARM)",
30+
"vcpus": 16,
31+
"memory": 32
32+
},
33+
"cpx11": { "name": "CPX11 (2 vCPU, 2 GB RAM)", "vcpus": 2, "memory": 2 },
34+
"cpx21": { "name": "CPX21 (3 vCPU, 4 GB RAM)", "vcpus": 3, "memory": 4 },
35+
"cpx31": { "name": "CPX31 (4 vCPU, 8 GB RAM)", "vcpus": 4, "memory": 8 },
36+
"cpx41": {
37+
"name": "CPX41 (8 vCPU, 16 GB RAM)",
38+
"vcpus": 8,
39+
"memory": 16
40+
},
41+
"cpx51": {
42+
"name": "CPX51 (16 vCPU, 32 GB RAM)",
43+
"vcpus": 16,
44+
"memory": 32
45+
},
1446
"cx22": {
1547
"name": "CX22 (2 vCPU, 4 GB RAM, AMD)",
1648
"vcpus": 2,
1749
"memory": 4
1850
},
19-
"cx31": { "name": "CX31 (2 vCPU, 8 GB RAM)", "vcpus": 2, "memory": 8 },
2051
"cx32": {
2152
"name": "CX32 (4 vCPU, 8 GB RAM, AMD)",
2253
"vcpus": 4,
2354
"memory": 8
2455
},
25-
"cx41": { "name": "CX41 (4 vCPU, 16 GB RAM)", "vcpus": 4, "memory": 16 },
2656
"cx42": {
2757
"name": "CX42 (8 vCPU, 16 GB RAM, AMD)",
2858
"vcpus": 8,
2959
"memory": 16
3060
},
31-
"cx51": { "name": "CX51 (8 vCPU, 32 GB RAM)", "vcpus": 8, "memory": 32 },
3261
"cx52": {
3362
"name": "CX52 (16 vCPU, 32 GB RAM, AMD)",
3463
"vcpus": 16,
@@ -63,31 +92,6 @@
6392
"name": "CCX63 (48 vCPU, 192 GB RAM, Dedicated)",
6493
"vcpus": 48,
6594
"memory": 192
66-
},
67-
"cpx11": {
68-
"name": "CPX11 (2 vCPU, 2 GB RAM, CPU-optimized)",
69-
"vcpus": 2,
70-
"memory": 2
71-
},
72-
"cpx21": {
73-
"name": "CPX21 (3 vCPU, 4 GB RAM, CPU-optimized)",
74-
"vcpus": 3,
75-
"memory": 4
76-
},
77-
"cpx31": {
78-
"name": "CPX31 (4 vCPU, 8 GB RAM, CPU-optimized)",
79-
"vcpus": 4,
80-
"memory": 8
81-
},
82-
"cpx41": {
83-
"name": "CPX41 (8 vCPU, 16 GB RAM, CPU-optimized)",
84-
"vcpus": 8,
85-
"memory": 16
86-
},
87-
"cpx51": {
88-
"name": "CPX51 (16 vCPU, 64 GB RAM, CPU-optimized)",
89-
"vcpus": 16,
90-
"memory": 64
9195
}
9296
},
9397
"images": {
@@ -114,8 +118,109 @@
114118
"alma-9": { "name": "AlmaLinux 9", "icon": "/icon/almalinux.svg" }
115119
}
116120
},
117-
"availability": {
118-
"ccx63": ["fsn1", "nbg1"],
119-
"*": ["fsn1", "nbg1", "hel1", "ash", "hil"]
121+
"availability_by_location": {
122+
"_comment": "Europe has ARM (CAX) + AMD (CX). USA/Asia only have Intel (CPX) + Dedicated (CCX).",
123+
"fsn1": [
124+
"cax11",
125+
"cax21",
126+
"cax31",
127+
"cax41",
128+
"cpx11",
129+
"cpx21",
130+
"cpx31",
131+
"cpx41",
132+
"cpx51",
133+
"cx22",
134+
"cx32",
135+
"cx42",
136+
"cx52",
137+
"ccx13",
138+
"ccx23",
139+
"ccx33",
140+
"ccx43",
141+
"ccx53",
142+
"ccx63"
143+
],
144+
"nbg1": [
145+
"cax11",
146+
"cax21",
147+
"cax31",
148+
"cax41",
149+
"cpx11",
150+
"cpx21",
151+
"cpx31",
152+
"cpx41",
153+
"cpx51",
154+
"cx22",
155+
"cx32",
156+
"cx42",
157+
"cx52",
158+
"ccx13",
159+
"ccx23",
160+
"ccx33",
161+
"ccx43",
162+
"ccx53",
163+
"ccx63"
164+
],
165+
"hel1": [
166+
"cax11",
167+
"cax21",
168+
"cax31",
169+
"cax41",
170+
"cpx11",
171+
"cpx21",
172+
"cpx31",
173+
"cpx41",
174+
"cpx51",
175+
"cx22",
176+
"cx32",
177+
"cx42",
178+
"cx52",
179+
"ccx13",
180+
"ccx23",
181+
"ccx33",
182+
"ccx43",
183+
"ccx53",
184+
"ccx63"
185+
],
186+
"ash": [
187+
"cpx11",
188+
"cpx21",
189+
"cpx31",
190+
"cpx41",
191+
"cpx51",
192+
"ccx13",
193+
"ccx23",
194+
"ccx33",
195+
"ccx43",
196+
"ccx53",
197+
"ccx63"
198+
],
199+
"hil": [
200+
"cpx11",
201+
"cpx21",
202+
"cpx31",
203+
"cpx41",
204+
"cpx51",
205+
"ccx13",
206+
"ccx23",
207+
"ccx33",
208+
"ccx43",
209+
"ccx53",
210+
"ccx63"
211+
],
212+
"sin": [
213+
"cpx11",
214+
"cpx21",
215+
"cpx31",
216+
"cpx41",
217+
"cpx51",
218+
"ccx13",
219+
"ccx23",
220+
"ccx33",
221+
"ccx43",
222+
"ccx53",
223+
"ccx63"
224+
]
120225
}
121226
}

registry/melmathari/templates/hetzner-cloud/main.tf

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ data "coder_workspace_owner" "me" {}
2929
# Load Hetzner Cloud configuration from JSON
3030
locals {
3131
hetzner_config = jsondecode(file("${path.module}/hetzner-config.json"))
32+
33+
# Generate server type options filtered by selected location
34+
server_type_options_for_selected_location = [
35+
for type_key in lookup(local.hetzner_config.availability_by_location, data.coder_parameter.location.value, []) : {
36+
name = local.hetzner_config.type_meta.server_types[type_key].name
37+
value = type_key
38+
}
39+
]
3240
}
3341

3442
# Hetzner Cloud locations parameter (dynamically generated from JSON)
@@ -52,7 +60,7 @@ data "coder_parameter" "location" {
5260
}
5361

5462

55-
# Hetzner Cloud server types parameter (dynamically generated from JSON)
63+
# Hetzner Cloud server types parameter (dynamically filtered based on selected location)
5664
data "coder_parameter" "server_type" {
5765
name = "server_type"
5866
display_name = "Server Type"
@@ -62,11 +70,12 @@ data "coder_parameter" "server_type" {
6270
icon = "/icon/memory.svg"
6371
mutable = false
6472

73+
# Filter server types based on the selected location
6574
dynamic "option" {
66-
for_each = local.hetzner_config.type_meta.server_types
75+
for_each = local.server_type_options_for_selected_location
6776
content {
6877
name = option.value.name
69-
value = option.key
78+
value = option.value.value
7079
}
7180
}
7281
}
@@ -133,21 +142,6 @@ locals {
133142
selected_server_type = local.hetzner_config.type_meta.server_types[data.coder_parameter.server_type.value]
134143
selected_location = local.hetzner_config.type_meta.locations[data.coder_parameter.location.value]
135144
network_zone = local.selected_location.zone
136-
137-
# Get availability for selected server type (use specific or wildcard)
138-
server_availability = lookup(local.hetzner_config.availability, data.coder_parameter.server_type.value, local.hetzner_config.availability["*"])
139-
140-
# Validate server type is available in selected location
141-
is_valid_combination = contains(local.server_availability, data.coder_parameter.location.value)
142-
}
143-
144-
# Validation check for server type and location compatibility
145-
resource "null_resource" "validate_server_location" {
146-
count = local.is_valid_combination ? 0 : 1
147-
148-
provisioner "local-exec" {
149-
command = "echo 'ERROR: Server type ${data.coder_parameter.server_type.value} is not available in location ${data.coder_parameter.location.value}' && exit 1"
150-
}
151145
}
152146

153147
resource "coder_agent" "main" {

0 commit comments

Comments
 (0)