Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp for managing cloud and on-premises infrastructure through declarative configuration files. Instead of clicking through provider consoles or writing procedural setup scripts, engineers define network topologies, virtual machines, databases, and security policies in human-readable text files using HashiCorp Configuration Language (HCL). Storing these definitions in version control systems like Git makes infrastructure changes auditable, repeatable, and consistent across environments.
How it works
The standard Terraform workflow follows three steps: writing configuration files, previewing changes with terraform plan, and provisioning resources with terraform apply. During execution, Terraform reads a state file (terraform.tfstate) that maps your configuration code to real-world resources. By comparing the desired configuration against the current state, Terraform calculates the exact actions needed to reach the target architecture.
This state-driven approach enforces idempotency—re-running the same configuration makes no changes if the live environment already matches the code. Terraform communicates with external platforms through plugins called providers, supporting thousands of services across AWS, Google Cloud, Microsoft Azure, Kubernetes, and DNS or CDN vendors. Teams also group configurations into reusable modules so identical network and server patterns can be deployed across development, staging, and production.
Example
A minimal main.tf configuration defines the cloud provider and declares a single virtual server instance:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "eu-west-3"
}
resource "aws_instance" "web_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = {
Name = "production-web"
}
}
Running terraform init downloads the AWS provider plugin, terraform plan confirms one server will be created, and terraform apply provisions the instance.
What matters when choosing a server or hosting
- Official provider support: Verify that your cloud or bare-metal host maintains an actively updated Terraform provider; without API coverage, you cannot automate server provisioning.
- Remote state storage: Choose hosting or object storage (such as Amazon S3 or GCS) that supports encryption and state locking so multiple engineers or CI/CD pipelines do not corrupt the state file simultaneously.
- API rate limits and provisioning speed: Frequent
terraform planruns query every managed resource; providers with strict API throttling or slow bare-metal boot cycles can bottleneck automated deployments. - Immutable image support: Hosting platforms that allow custom machine images (AMIs, snapshots, or cloud-init templates) pair best with Terraform, reducing reliance on fragile post-boot configuration scripts.
Common mistakes
- Committing state files to Git: State files often contain plaintext database passwords, API keys, and sensitive metadata, and storing them in Git causes merge conflicts across teams.
- Making manual console edits (configuration drift): Modifying firewall rules or server sizes directly in a web dashboard causes the live infrastructure to diverge from the state file, leading Terraform to overwrite or destroy manual fixes on the next run.
- Putting all resources in one monolithic file: Managing an entire organization's network, databases, and applications in a single state file increases blast radius and slows down plan execution.
FAQ
What is the difference between Terraform and Ansible?
Terraform is primarily an infrastructure provisioning tool that creates, updates, and destroys cloud resources like networks and virtual machines. Ansible is a configuration management tool focused on installing software, updating packages, and configuring files inside already-running servers.
Is Terraform still completely open source?
HashiCorp changed Terraform's license to the Business Source License (BSL), which remains free for internal and non-competing commercial use. In response, the Linux Foundation launched OpenTofu, a fully open-source fork that maintains compatibility with Terraform configurations and providers.
Can Terraform manage bare-metal or on-premises servers?
Yes. While most commonly used for public clouds, Terraform includes providers for virtualization platforms like VMware vSphere and Proxmox, as well as bare-metal provisioning tools such as MAAS and Tinkerbell.