Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a2c192

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

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
}
27+
28+
variable "instance_location" {
29+
description = "What region should your workspace live in?"
30+
default = "nbg1"
31+
validation {
32+
condition = contains(["nbg1", "fsn1", "hel1"], var.instance_location)
33+
error_message = "Invalid zone!"
34+
}
35+
}
36+
37+
variable "instance_type" {
38+
description = "What instance type should your workspace use?"
39+
default = "cx11"
40+
validation {
41+
condition = contains(["cx11", "cx21", "cx31", "cx41", "cx51"], var.instance_type)
42+
error_message = "Invalid instance type!"
43+
}
44+
}
45+
46+
variable "instance_os" {
47+
description = "Which operating system should your workspace use?"
48+
default = "ubuntu-20.04"
49+
validation {
50+
condition = contains(["ubuntu-22.04","ubuntu-20.04", "ubuntu-18.04", "debian-11", "debian-10", "fedora-35"], var.instance_os)
51+
error_message = "Invalid OS!"
52+
}
53+
}
54+
55+
variable "volume_size" {
56+
description = "How much storage space do you need?"
57+
default = "50"
58+
validation {
59+
condition = contains(["50","100","150"], var.volume_size)
60+
error_message = "Invalid volume size!"
61+
}
62+
}
63+
64+
data "coder_workspace" "me" {
65+
}
66+
67+
resource "coder_agent" "dev" {
68+
arch = "amd64"
69+
os = "linux"
70+
}
71+
72+
resource "hcloud_server" "root" {
73+
count = data.coder_workspace.me.start_count
74+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
75+
server_type = var.instance_type
76+
location = var.instance_location
77+
image = var.instance_os
78+
user_data = <<EOF
79+
#!/bin/bash
80+
mkdir /home/coder/
81+
mount -o discard,defaults /dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id} /home/coder/
82+
export CODER_AGENT_TOKEN=${coder_agent.dev.token}
83+
${coder_agent.dev.init_script}
84+
EOF
85+
}
86+
87+
resource "hcloud_volume" "root" {
88+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
89+
size = var.volume_size
90+
format = "ext4"
91+
location = var.instance_location
92+
}
93+
94+
resource "hcloud_volume_attachment" "root" {
95+
count = data.coder_workspace.me.start_count
96+
volume_id = hcloud_volume.root.id
97+
server_id = hcloud_server.root[count.index].id
98+
automount = false
99+
}
100+
101+
resource "hcloud_firewall" "root" {
102+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
103+
rule {
104+
direction = "in"
105+
protocol = "icmp"
106+
source_ips = [
107+
"0.0.0.0/0",
108+
"::/0"
109+
]
110+
}
111+
}
112+
113+
resource "hcloud_firewall_attachment" "root_fw_attach" {
114+
count = data.coder_workspace.me.start_count
115+
firewall_id = hcloud_firewall.root.id
116+
server_ids = [hcloud_server.root[count.index].id]
117+
}

0 commit comments

Comments
 (0)