The 30 second answer
Infrastructure as code means the network, clusters and managed services are declared in files, reviewed and applied, instead of clicked in a console. Terraform is a common tool for that: I write .tf files, terraform plan shows the diff against state, and terraform apply makes the change. State records what Terraform already created, so it must be stored remotely and locked. I keep secrets out of state when I can, and I split stacks so a typo in one file does not recreate the database.
Infrastructure as code (IaC) is the practice of describing infrastructure in versioned files so a change is reviewable and repeatable. Terraform, from HashiCorp, is one implementation: providers talk to APIs (AWS, GCP, Kubernetes), resources are declared, and a state file maps those declarations to real IDs.
The loop is:
- Write or change
.tffiles. terraform plancompares configuration with state and shows what would be added, changed or destroyed.terraform applyperforms that plan.
State is sensitive and must not live only on a laptop. HashiCorp documents remote backends and state locking so two applies cannot race. I also treat a database as a carefully protected resource (prevent_destroy, a separate state) so an accidental apply cannot replace it.
terraform {
required_version = ">= 1.5.0"
backend "s3" {
bucket = "shop-terraform"
key = "checkout/prod/terraform.tfstate"
region = "eu-central-1"
}
}
resource "aws_s3_bucket" "invoices" {
bucket = "shop-invoices-prod"
}Terraform is not a substitute for application CI, and it is not the only IaC tool (CloudFormation, Pulumi, Kubernetes manifests are others). I would say "IaC" first, then name Terraform as the tool I use for cloud resources.
Sources (3)
- Terraform: What is Terraformdeveloper.hashicorp.com
- Terraform: The plan and apply workflowdeveloper.hashicorp.com
- Terraform: Statedeveloper.hashicorp.com