Skip to content

add Hetzner Cloud Template #226

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .icons/Hetzner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions registry/Harsh9485/templates/Hetzner-Cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
display_name: "Hetzner Cloud Template"
description: "A complete Coder template to provision Hetzner Cloud virtual machines with private networking and attached volumes."
icon: "../../../../.icons/Hetzner.svg"
verified: false
tags: ["hetzner", "cloud", "vm", "infrastructure"]
---

# Hetzner Cloud Template

This template provisions one or more Hetzner Cloud virtual machines with:
- Private network
- Attached volumes
- Coder agent

It is designed to be used directly by Coder to spin up full workspaces on Hetzner Cloud.

## Requirements
- Hetzner Cloud account
- Hetzner Cloud API token (can be added via environment variable or Terraform variable)

## Usage

To test this template:

```sh
coder templates push hetzner-cloud -d .
```
77 changes: 77 additions & 0 deletions registry/Harsh9485/templates/Hetzner-Cloud/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
terraform {
required_version = ">= 1.0"

required_providers {
coder = {
source = "coder/coder"
version = ">= 2.5"
}
hcloud = {
source = "hetznercloud/hcloud"
version = ">= 1.50"
}
}
}

provider "hcloud" {
token = var.hcloud_token
}

data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

resource "hcloud_network" "private" {
name = "workspace-net-${data.coder_workspace.me.id}"
ip_range = var.network_cidr
}

resource "hcloud_network_subnet" "private" {
network_id = hcloud_network.private.id
type = "server"
network_zone = var.location
ip_range = var.network_cidr
}

resource "hcloud_server" "dev" {
count = var.instances
name = "dev-${count.index}-${data.coder_workspace.me.id}"
image = var.image
server_type = var.server_type
location = var.location
ssh_keys = []

user_data = <<-EOT
#!/bin/bash
curl -fsSL https://get.coder.com -o coder.sh
bash coder.sh
EOT
}

resource "hcloud_volume" "dev_data" {
count = var.instances
name = "volume-${count.index}-${data.coder_workspace.me.id}"
size = var.volume_size
server_id = hcloud_server.dev[count.index].id
}

resource "hcloud_server_network" "connect" {
count = var.instances
server_id = hcloud_server.dev[count.index].id
network_id = hcloud_network.private.id
ip = cidrhost(var.network_cidr, count.index + 10)
}

resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
startup_script = <<-EOT
echo "Coder agent started on Hetzner VM"
EOT
}

module "code-server" {
source = "registry.coder.com/coder/code-server/coder"
version = "~> 1.0"
agent_id = coder_agent.main.id
}
Loading