Skip to content

Commit bdbde49

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

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = "~> 0.3.1"
6+
}
7+
hcloud = {
8+
source = "hetznercloud/hcloud"
9+
version = "~> 1.33.1"
10+
}
11+
}
12+
}
13+
14+
data "coder_workspace" "me" {
15+
}
16+
17+
resource "coder_agent" "dev" {
18+
arch = "amd64"
19+
os = "linux"
20+
}
21+
22+
variable "hcloud_token" {
23+
description = <<EOF
24+
Coder requires a Hetzner Cloud token to provision workspaces.
25+
EOF
26+
sensitive = true
27+
}
28+
29+
variable "instance_location" {
30+
description = "What region should your workspace live in?"
31+
default = "nbg1"
32+
validation {
33+
condition = contains(["nbg1", "fsn1", "hel1"], var.instance_location)
34+
error_message = "Invalid zone!"
35+
}
36+
}
37+
38+
variable "instance_type" {
39+
description = "What instance type should your workspace use?"
40+
default = "cx11"
41+
validation {
42+
condition = contains(["cx11", "cx21", "cx31", "cx41", "cx51"], var.instance_type)
43+
error_message = "Invalid zone!"
44+
}
45+
}
46+
47+
variable "instance_os" {
48+
description = "Which operating system should your workspace use?"
49+
default = "ubuntu-20.04"
50+
validation {
51+
condition = contains(["ubuntu-20.04", "ubuntu-18.04", "debian-11", "debian-10", "fedora-35"], var.instance_os)
52+
error_message = "Invalid zone!"
53+
}
54+
}
55+
56+
57+
provider "hcloud" {
58+
token = var.hcloud_token
59+
}
60+
61+
resource "hcloud_server" "root" {
62+
count = data.coder_workspace.me.start_count
63+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
64+
server_type = var.instance_type
65+
location = var.instance_location
66+
image = var.instance_os
67+
user_data = <<EOF
68+
#!/bin/bash
69+
export CODER_TOKEN=${coder_agent.dev.token}
70+
${coder_agent.dev.init_script}"
71+
EOF
72+
}
73+
74+
resource "hcloud_volume" "root" {
75+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
76+
size = 50
77+
format = "ext4"
78+
location = var.instance_location
79+
}
80+
81+
resource "hcloud_volume_attachment" "root" {
82+
count = data.coder_workspace.me.start_count
83+
volume_id = hcloud_volume.root.id
84+
server_id = hcloud_server.root[count.index].id
85+
automount = true
86+
}

0 commit comments

Comments
 (0)