Infrastructure built by hand in a cloud console is hard to repeat and easy to get wrong. Nobody remembers exactly which settings were chosen, test and production drift apart, and rebuilding after a mistake takes days. Infrastructure as code fixes this by describing networks, servers, databases and permissions in files that are reviewed, versioned and applied like any other code.
Terraform is the most widely used tool for this. You write configuration in HCL, a readable language of blocks: a provider block says which platform you are working with, such as AWS or Azure, and resource blocks describe what should exist, such as a virtual network, a storage bucket or a Kubernetes cluster. The same tool and the same workflow work across clouds.
The workflow has four commands. terraform init downloads the providers your configuration needs. terraform plan compares your files with what actually exists and shows exactly what would be created, changed or destroyed. terraform apply makes those changes after you confirm. terraform destroy removes everything the configuration manages, which is handy for short-lived test environments.
The plan is the heart of it. Because you see every change before it happens, a reviewer can check the plan in a pull request just as they would check code. In a pipeline, a common pattern is to run plan on every pull request, post the result for review, and run apply only after the change is merged and approved.
Terraform remembers what it created in a state file. On a team, that file must not live on one person's laptop. Store it in a remote backend, such as an S3 bucket on AWS or a storage account on Azure, with locking switched on so two people cannot apply changes at the same time. Treat the state as sensitive: it can contain secrets, so restrict who can read it.
As the configuration grows, use variables for anything that changes between environments, such as instance sizes or names, and outputs to expose values other configurations need. Group related resources into modules, for example one module for a standard network, and reuse it for test, staging and production. The environments then differ only in their inputs, not in hand-written copies.
Keep secrets out of your .tf files and out of Git, pin provider versions so an upgrade never surprises you, and run terraform fmt and terraform validate in your pipeline to catch mistakes early. When someone changes a resource by hand, the next plan will show the drift, so you can bring the code and the cloud back in line.
Terraform pairs naturally with a CI/CD pipeline: the same GitHub Actions workflow that tests your app can plan and apply the infrastructure it runs on. Our DevOps course covers Terraform hands-on, from your first resource to reusable modules and remote state.





