Skip to content

noaahh/valheim-hetzner-iac

Repository files navigation

valheim-hetzner-iac

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.

Overview

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.

Prerequisites

Ansible Dependencies

External Ansible components are managed via requirements.yml.

Roles

Collections

  • community.docker Used to manage Docker Compose v2 deployments.

Install all dependencies with:

ansible-galaxy install -r requirements.yml

Configuration

Terraform Variables

Required:

  • hcloud_token (recommended via TF_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 Configuration

Valheim server settings are defined as Ansible defaults in:

roles/valheim_server/defaults/main.yml

This 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.

Usage

  1. Install Ansible Galaxy dependencies:
ansible-galaxy install -r requirements.yml
  1. Initialize Terraform:
terraform init
  1. Apply the configuration:
terraform apply

Outputs

After 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.

About

Terraform and Ansible configuration for a Valheim server on Hetzner Cloud.

Resources

Stars

Watchers

Forks

Contributors