Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe89a0e

Browse files
committed
example: added hetzner cloud workspace
1 parent6dedd0c commitbe89a0e

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-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+
---
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#cloud-config
2+
users:
3+
- name: ${username}
4+
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
5+
groups: sudo
6+
shell:/bin/bash
7+
packages:
8+
- git
9+
mounts:
10+
- [
11+
"${volume_path}",
12+
"/home/${username}",
13+
ext4,
14+
"discard,defaults",
15+
]
16+
write_files:
17+
-path:/opt/coder/init
18+
permissions:"0755"
19+
encoding: b64
20+
content: ${init_script}
21+
-path:/etc/systemd/system/coder-agent.service
22+
permissions:"0644"
23+
content: |
24+
[Unit]
25+
Description=Coder Agent
26+
After=network-online.target
27+
Wants=network-online.target
28+
29+
[Service]
30+
User=${username}
31+
ExecStart=/opt/coder/init
32+
Environment=CODER_AGENT_TOKEN=${coder_agent_token}
33+
Restart=always
34+
RestartSec=10
35+
TimeoutStopSec=90
36+
KillMode=process
37+
38+
OOMScoreAdjust=-900
39+
SyslogIdentifier=coder-agent
40+
41+
[Install]
42+
WantedBy=multi-user.target
43+
runcmd:
44+
- chown ${username}:${username}/home/${username}
45+
- systemctl enable coder-agent
46+
- systemctl start coder-agent

‎examples/hetzner-linux/main.tf

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
terraform {
2+
required_providers {
3+
coder={
4+
source="coder/coder"
5+
version="0.4.2"
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=templatefile("cloud-config.yaml.tftpl", {
83+
username= data.coder_workspace.me.owner
84+
volume_path="/dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id}"
85+
init_script=base64encode(coder_agent.dev.init_script)
86+
coder_agent_token= coder_agent.dev.token
87+
})
88+
}
89+
90+
resource"hcloud_volume""root" {
91+
name="coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
92+
size=var.volume_size
93+
format="ext4"
94+
location=var.instance_location
95+
}
96+
97+
resource"hcloud_volume_attachment""root" {
98+
count=data.coder_workspace.me.start_count
99+
volume_id=hcloud_volume.root.id
100+
server_id=hcloud_server.root[count.index].id
101+
automount=false
102+
}
103+
104+
resource"hcloud_firewall""root" {
105+
name="coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
106+
rule {
107+
direction="in"
108+
protocol="icmp"
109+
source_ips=[
110+
"0.0.0.0/0",
111+
"::/0"
112+
]
113+
}
114+
}
115+
116+
resource"hcloud_firewall_attachment""root_fw_attach" {
117+
count=data.coder_workspace.me.start_count
118+
firewall_id=hcloud_firewall.root.id
119+
server_ids=[hcloud_server.root[count.index].id]
120+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp