Back to Blog
team@tinypod.app

Terraform for Self-Hosted Infrastructure

Terraform provisions infrastructure as code. Servers, DNS, firewalls — all defined in files, versioned in git, and reproducible.

terraformiacinfrastructuredevops

What Is Terraform?


Terraform is an infrastructure-as-code tool. Instead of clicking through a web console to create a server, you describe the desired infrastructure in configuration files and Terraform creates it.


Why Use Terraform?


Reproducibility

Your entire infrastructure is defined in code. Destroy everything and recreate it from the same files.


Version Control

Infrastructure changes are tracked in git. Review, approve, and roll back infrastructure changes like code changes.


Documentation

The Terraform files ARE the documentation. No more "how was this server configured?" — read the code.


Multi-Provider

Manage resources across Hetzner, Cloudflare, AWS, and more from one tool.


Self-Hosting Example


Server + DNS + Firewall


resource "hcloud_server" "web" {

name = "tinypod-web"

server_type = "cx22"

image = "ubuntu-24.04"

location = "fsn1"

}


resource "cloudflare_record" "web" {

zone_id = var.cloudflare_zone_id

name = "app"

value = hcloud_server.web.ipv4_address

type = "A"

proxied = true

}


resource "hcloud_firewall" "web" {

name = "web-firewall"

rule {

direction = "in"

protocol = "tcp"

port = "80"

source_ips = ["0.0.0.0/0"]

}

rule {

direction = "in"

protocol = "tcp"

port = "443"

source_ips = ["0.0.0.0/0"]

}

}


Run terraform apply and Terraform creates the server, DNS record, and firewall rules.


Terraform vs Alternatives


Terraform vs Ansible

  • Terraform: Creates infrastructure (servers, networks, DNS)
  • Ansible: Configures infrastructure (installs software, edits configs)
  • Use both: Terraform creates, Ansible configures

  • Terraform vs Pulumi

  • Terraform: HCL language, massive provider ecosystem
  • Pulumi: Real programming languages (TypeScript, Python, Go)
  • Terraform for wider adoption, Pulumi for programming language preference

  • State Management


    Terraform keeps a state file tracking what it manages. Store it securely:

  • S3 with encryption for remote state
  • Never commit terraform.tfstate to git (contains secrets)

  • Getting Started


    1. Install Terraform

    2. Define your provider (Hetzner, DigitalOcean, AWS)

    3. Write resource definitions

    4. terraform plan (preview changes)

    5. terraform apply (create resources)

    6. Commit .tf files to git


    Pair with TinyPod: use Terraform to provision the server, TinyPod to manage the applications on it.