Skip to content

example: added hetzner cloud workspace #1884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
example: added Code-Server installation to hetzner template
  • Loading branch information
ntimo committed Jun 9, 2022
commit dd57b0eca790e30e988a89ceb6be41dd1e377e76
26 changes: 26 additions & 0 deletions examples/hetzner-linux/cloud-config.yaml.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ users:
shell: /bin/bash
packages:
- git
- curl
- jq
mounts:
- [
"${volume_path}",
Expand Down Expand Up @@ -40,7 +42,31 @@ write_files:

[Install]
WantedBy=multi-user.target
%{ if code_server_setup ~}
- path: /tmp/install_code_server.sh
permissions: "0777"
content: |
#!/bin/bash
CODE_SERVER_DOWNLOAD_URL=$(curl -sL https://api.github.com/repos/coder/code-server/releases/latest | jq -r '.assets[].browser_download_url' | grep "amd64.deb")
curl -fL $CODE_SERVER_DOWNLOAD_URL -o /tmp/code_server.deb
dpkg -i /tmp/code_server.deb
systemctl enable --now code-server@${username}
rm /tmp/code_server.deb
- path: /tmp/install_code_server.sh
permissions: "0777"
content: |
- path: /home/${username}/.config/code-server/config.yaml
permissions: "0644"
content: |
bind-addr: 127.0.0.1:8080
auth: none
cert: false
%{ endif ~}
runcmd:
- chown ${username}:${username} /home/${username}
- systemctl enable coder-agent
- systemctl start coder-agent
%{ if code_server_setup ~}
- /tmp/install_code_server.sh
- rm /tmp/install_code_server.sh
%{ endif }
23 changes: 21 additions & 2 deletions examples/hetzner-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ variable "volume_size" {
}
}

variable "code_server" {
description = "Should Code Server be installed?"
default = "true"
validation {
condition = contains(["true","false"], var.code_server)
error_message = "Your answer can only be yes or no!"
}
}

data "coder_workspace" "me" {
}

Expand All @@ -73,17 +82,27 @@ resource "coder_agent" "dev" {
os = "linux"
}

resource "coder_app" "code-server" {
count = var.code_server ? 1 : 0
agent_id = coder_agent.dev.id
name = "code-server"
icon = "https://cdn.icon-icons.com/icons2/2107/PNG/512/file_type_vscode_icon_130084.png"
url = "http://localhost:8080"
relative_path = true
}

resource "hcloud_server" "root" {
count = data.coder_workspace.me.start_count
count = data.coder_workspace.me.start_count
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
server_type = var.instance_type
location = var.instance_location
image = var.instance_os
user_data = templatefile("cloud-config.yaml.tftpl", {
user_data = templatefile("cloud-config.yaml.tftpl", {
username = data.coder_workspace.me.owner
volume_path = "/dev/disk/by-id/scsi-0HC_Volume_${hcloud_volume.root.id}"
init_script = base64encode(coder_agent.dev.init_script)
coder_agent_token = coder_agent.dev.token
code_server_setup = var.code_server
})
}

Expand Down