Provision and deploy a Valheim dedicated server on Hetzner Cloud using Terraform and Ansible.
The server is deployed as a Docker container and fully managed through Infrastructure as Code. Terraform is responsible for infrastructure provisioning, while Ansible handles system configuration, security hardening, and application deployment.
This repository automates the following:
- Creation of a Hetzner Cloud server, firewall, and optional floating IP
- Secure SSH access restricted to the provisioning host
- Base system setup and user management
- Docker installation and configuration
- Deployment of a Valheim server via Docker Compose
Terraform orchestrates the full flow and invokes Ansible playbooks as part of the apply phase.
External Ansible components are managed via requirements.yml.
-
geerlingguy.docker Installs and configures Docker on the target host.
-
geerlingguy.security Applies baseline system hardening, including SSH configuration and automatic updates.
- community.docker Used to manage Docker Compose v2 deployments.
Install all dependencies with:
ansible-galaxy install -r requirements.ymlRequired:
hcloud_token(recommended viaTF_VAR_hcloud_token)ssh_public_key_path
Optional variables allow configuration of:
- Server type and location
- Floating IP usage
- Project and environment labels
Defaults are defined in variables.tf.
Valheim server settings are defined as Ansible defaults in:
roles/valheim_server/defaults/main.ymlThis includes:
- Server name and world name
- Server password
- Public visibility
- Timezone
- Backup behavior
- Optional Valheim Plus support
Changes to these values can be applied by re-running Terraform or the Ansible playbook directly.
- Install Ansible Galaxy dependencies:
ansible-galaxy install -r requirements.yml- Initialize Terraform:
terraform init- Apply the configuration:
terraform applyAfter a successful apply, Terraform outputs:
- Server IPv4 address
- Floating IP address (if enabled)
These can be used for connecting to the server or configuring DNS.