Back to Blog
team@tinypod.app

Terraform for Self-Hosting: Infrastructure as Code

Define your self-hosted infrastructure in code. Reproducible, version-controlled, and automated server provisioning.

terraformiacdevops

What Is Infrastructure as Code?


Infrastructure as Code (IaC) means defining your servers, networks, and services in configuration files instead of clicking through web consoles. It's version-controlled, reproducible, and automated.


Why IaC for Self-Hosting?


Reproducibility

Destroy everything and recreate it from code. Perfect for disaster recovery and testing.


Documentation

Your infrastructure is documented by the code itself. No guessing about how things are configured.


Version Control

Track changes over time. Roll back if something breaks.


Automation

No manual setup. Run one command and your entire infrastructure is provisioned.


Terraform Basics


Terraform uses HCL (HashiCorp Configuration Language) to define resources:


Provider

Tells Terraform which cloud platform to use: Hetzner, DigitalOcean, AWS, etc.


Resource

Defines infrastructure: servers, DNS records, firewalls.


Variable

Parameterizes your configuration: server size, region, domain name.


Output

Extracts information: server IP address, DNS name.


Common Terraform for Self-Hosting


Provision a VPS

Create a server on Hetzner/DigitalOcean with specific CPU, RAM, and storage.


Configure DNS

Create A records pointing your domain to the server.


Set Up Firewall

Allow SSH, HTTP, HTTPS. Block everything else.


Bootstrap the Server

Install Docker/Podman, Caddy, and your application stack via cloud-init or provisioners.


When Terraform Is Worth It


  • Managing 3+ servers
  • Frequently creating/destroying test environments
  • Multi-cloud setups
  • Team-managed infrastructure

  • When It's Overkill


  • One server for personal use
  • Rarely changing infrastructure
  • Using a managed platform like TinyPod (we handle the infrastructure)

  • The Middle Ground


    Use TinyPod for application deployment (one-click, managed) and Terraform for any custom infrastructure around it (DNS, monitoring, VPN).