Self-Hosted Agents — Terraform Setup¶
This page describes an Infrastructure as Code path for the same Hetzner-based agents covered in the self-hosted agents overview. Use it when you want reproducible servers, version-controlled configuration, and easier scaling.
When to use Terraform¶
- Production or long-lived agent farms
- Multiple environments (e.g. staging vs production pools) with the same shape
- Team ownership of infrastructure with review via pull requests
For a fast first setup or learning path, use the manual guides: Linux and Windows.
Prerequisites¶
- Terraform installed locally or in a pipeline
- Hetzner Cloud API token with permission to create servers and networks
- SSH keys (Linux) and RDP access patterns as described in Connection and Authentication
- Azure DevOps organization permissions to register agents and manage pools (see Agent Pools Configuration)
High-level flow¶
- Define Hetzner server resources (type, image, location, SSH keys) using the Hetzner Terraform provider.
- Apply the configuration to create or update VMs.
- On each VM, install and configure the Azure Pipelines agent (same as the manual guides).
- Register agents into the appropriate agent pools.
Organization-specific modules
Terraform root modules and state backends differ per team (remote state, naming, tagging). Keep module source in your organization’s Git repository; this documentation site only documents the integration pattern with Azure DevOps and Hetzner.
Related documentation¶
- Overview — architecture, cost notes, and quick start
- Linux Setup / Windows Setup — agent installation after VMs exist
- Agent Pools Configuration
- Terraform Hetzner provider