Skip to content
/ hcloud Public

VPS management on Hetzner Cloud using Terraform and cloud-init

License

Notifications You must be signed in to change notification settings

cwc1222/hcloud

Repository files navigation

hcloud

VPS management on Hetzner Cloud

Quick Start

# Install wrangler to interact with cloudflare
bun install
# Create the R2 bucket to store the terraform state
bun run create

# export PG_CONN_STR=postgres://user:pass@db.example.com/terraform
# terraform init

# Remember to fill the cloudflare R2 bucket info in backend.hcl
# bun run create // create r2 bucket tokens
# cp backend.hcl.example backend.hcl // fill the previous output secrets to this file
terraform init -backend-config=backend.hcl
terraform plan
terraform apply
terraform destroy

How to find available images

  1. Use curl
curl \
	-H "Authorization: Bearer $H_API_TOKEN" \
	"https://api.hetzner.cloud/v1/images"

curl \
	-H "Authorization: Bearer $H_API_TOKEN" \
	"https://api.hetzner.cloud/v1/images/$ID"
  1. Use hcloud cli
hcloud context create <ur-project-name>
hcloud image list -t system -a x86

SSH Tunnels

To access the remote Postgres and K3S cluster without modifying the firewall rules, which only open 80, 443, and ssh for security concerns, we can use the ssh tunnel enabling the connection from the local machine to the remote services.

The sshtunnels folder has the systemd configurations and installation bash, following the commands will install the systemd services.

cd sshtunnels/
# Ensure the SSH_USER and REMOTE_HOST are configured in tne env
# e.g., 
# - export SSH_USER=xxx
# - export REMOTE_HOST=xxx
bash install_tunnel.sh

# Check the install services
systemctl status --user postgres-tunnel.service
systemctl status --user k3s-ssh-tunnel.service
# To see the logs
journalctl --user --unit=postgres-tunnel.service --no-pager
journalctl --user --unit=k3s-ssh-tunnel.service --no-pager

Reference

About

VPS management on Hetzner Cloud using Terraform and cloud-init

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published