Skip to content

Commit 49ff3a3

Browse files
committed
example: added hetzner cloud workspace
1 parent 6dedd0c commit 49ff3a3

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

examples/hetzner-linux/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: Develop in Linux on Hetzner Cloud
3+
description: Get started with Linux development on Hetzner Cloud.
4+
tags: [cloud, hetzner]
5+
---

examples/hetzner-linux/main.tf

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = "0.4.1"
6+
}
7+
hcloud = {
8+
source = "hetznercloud/hcloud"
9+
version = "1.33.2"
10+
}
11+
}
12+
}
13+
14+
provider "hcloud" {
15+
token = var.hcloud_token
16+
}
17+
18+
provider "coder" {
19+
}
20+
21+
variable "hcloud_token" {
22+
description = <<EOF
23+
Coder requires a Hetzner Cloud token to provision workspaces.
24+
EOF
25+
sensitive = true
26+
validation {
27+
condition = length(var.hcloud_token) == 64
28+
error_message = "Please provide a valid Hetzner Cloud API token."
29+
}
30+
}
31+
32+
variable "instance_location" {
33+
description = "What region should your workspace live in?"
34+
default = "nbg1"
35+
validation {
36+
condition = contains(["nbg1", "fsn1", "hel1"], var.instance_location)
37+
error_message = "Invalid zone!"
38+
}
39+
}
40+
41+
variable "instance_type" {
42+
description = "What instance type should your workspace use?"
43+
default = "cx11"
44+
validation {
45+
condition = contains(["cx11", "cx21", "cx31", "cx41", "cx51"], var.instance_type)
46+
error_message = "Invalid instance type!"
47+
}
48+
}
49+
50+
variable "instance_os" {
51+
description = "Which operating system should your workspace use?"
52+
default = "ubuntu-20.04"
53+
validation {
54+
condition = contains(["ubuntu-22.04","ubuntu-20.04", "ubuntu-18.04", "debian-11", "debian-10", "fedora-35"], var.instance_os)
55+
error_message = "Invalid OS!"
56+
}
57+
}
58+
59+
variable "volume_size" {
60+
description = "How much storage space do you need?"
61+
default = "50"
62+
validation {
63+
condition = contains(["50","100","150"], var.volume_size)
64+
error_message = "Invalid volume size!"
65+
}
66+
}
67+
68+
data "coder_workspace" "me" {
69+
}
70+
71+
resource "coder_agent" "dev" {
72+
arch = "amd64"
73+
os = "linux"
74+
}
75+
76+
resource "hcloud_server" "root" {
77+
count = data.coder_workspace.me.start_count
78+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
79+
server_type = var.instance_type
80+
location = var.instance_location
81+
image = var.instance_os
82+
user_data = <<EOF
83+
#!/bin/bash
84+
mkdir /home/coder/
85+
mount -o discard,defaults /dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id} /home/coder/
86+
export CODER_AGENT_TOKEN=${coder_agent.dev.token}
87+
${coder_agent.dev.init_script}
88+
EOF
89+
}
90+
91+
resource "hcloud_volume" "root" {
92+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
93+
size = var.volume_size
94+
format = "ext4"
95+
location = var.instance_location
96+
}
97+
98+
resource "hcloud_volume_attachment" "root" {
99+
count = data.coder_workspace.me.start_count
100+
volume_id = hcloud_volume.root.id
101+
server_id = hcloud_server.root[count.index].id
102+
automount = false
103+
}
104+
105+
resource "hcloud_firewall" "root" {
106+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
107+
rule {
108+
direction = "in"
109+
protocol = "icmp"
110+
source_ips = [
111+
"0.0.0.0/0",
112+
"::/0"
113+
]
114+
}
115+
}
116+
117+
resource "hcloud_firewall_attachment" "root_fw_attach" {
118+
count = data.coder_workspace.me.start_count
119+
firewall_id = hcloud_firewall.root.id
120+
server_ids = [hcloud_server.root[count.index].id]
121+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy