Compute on cloud is a bit overpriced for side-projects. So here is a simple terraform setup for a docker swarm on Hetzner VPS (4.66€/mo for 4GB + 2vCPU 👌🏻). It uses cloud-init to automate creation:
- server, with public IPv4
- access and deploy users
- firewall
- docker swarm
Create a Hetzner token in Security > API Tokens and put hcloud_token = YOUR_TOKEN
into terraform.tfvars
file.
terraform init
terraform apply -auto-approve
terraform output -raw access_key | ssh-add - <<< "access@$(terraform output -raw ip)"
ssh access@$(terraform output -raw ip)
terraform output -raw deploy_key | ssh-add - <<< "deploy@$(terraform output -raw ip)"
docker context create vps --docker "host=ssh://deploy@$(terraform output -raw ip)"
docker context use vps
docker stack deploy -c compose.yaml example