/TerraformHcloudConfig

Terraform scripts to create nodes in Hetzner Cloud

Primary LanguageHCL

Terraform Hetzner Cloud Config

These Terraform scripts create three nodes in Hetzner Cloud, attach a private network to them and create three volumes for each node. Then it creates an Ansible inventory and a script to renew the SSH host entries.

How to use it

  1. Clone repository
  2. Change SSH key name in main.tf (line with ssh_keys)
    The key has to exist in the Hetzner Cloud instance
  3. Select OS and TF/OT, for other combinations adjust:

With Terraform on Linux/MacOS

Terraform has to be installed.

  1. terraform init -upgrade
  2. export HCLOUD_TOKEN=<token>
  3. terraform plan -var hcloud_token=$HCLOUD_TOKEN
  4. terraform apply -var hcloud_token=$HCLOUD_TOKEN -auto-approve
  5. Use the inventory file 'inventory.yaml' with Ansible
  6. terraform destroy -var hcloud_token=$HCLOUD_TOKEN -auto-approve

With OpenTofu on Windows

Within PowerShell

  1. Install OpenTofu: winget install OpenTofu.Tofu
  2. tofu init -upgrade
  3. $Env:HCLOUD_TOKEN = "<token>"
  4. tofu plan -var hcloud_token=$Env:HCLOUD_TOKEN
  5. tofu apply -var hcloud_token=$Env:HCLOUD_TOKEN -auto-approve
  6. Use the inventory file 'inventory.yaml' with Ansible
  7. tofu destroy -var hcloud_token=$Env:HCLOUD_TOKEN -auto-approve

Install RKE2

  1. ansible-galaxy install lablabs.rke2
  2. ansible-playbook -i inventory.yaml rke2.yml