Infrastructure as Code
A way to create and manage servers, networks, and other resources from files rather than by hand. Teams can track those files in version control and review changes before applying them.
Also known as: IaC
What is Infrastructure as Code?
Infrastructure as Code (IaC) means managing infrastructure through configuration files or programs. Instead of clicking through a cloud console to set up a test environment, you describe the resources in a repository and let a tool make the API calls. Reviewers can see what changed in a pull request, and the same definition can be used to build another environment. Terraform is one IaC tool, not a synonym for the practice.
Desired state and actual state
With a declarative tool, you describe the result you want, such as a network with a particular address range. The tool works out which operations are needed. An imperative script specifies the steps instead: create the network, then add a subnet. Both can be IaC, but the script author may need to add checks so rerunning it doesn't create duplicates.
Terraform uses a state record to map resource addresses in the configuration to actual objects, such as a network with a specific cloud resource ID. A normal terraform plan reads that state and queries the provider to show the changes it proposes. terraform apply performs the changes. An apply isn't an all-or-nothing transaction: if it fails partway through, earlier operations may already have succeeded.
Example: a network in AWS
resource "aws_vpc" "app" {
cidr_block = "10.20.0.0/16"
tags = { Name = "app-network" }
}
With the AWS provider configured, this block tells Terraform to manage a virtual private cloud. On a fresh deployment the plan proposes creating it. After a successful apply, if nothing relevant has changed, the next plan should show no changes rather than propose a second VPC. That repeatable behavior is what engineers mean by idempotency here.
How teams use it
Teams manage networks, load balancers, and databases this way. Staging and production can use the same Terraform module with different inputs and separate state, so applying a staging change doesn't also update production. In a CI/CD pipeline, teams often review a plan and require approval for production changes. Shared state belongs in a restricted remote backend with locking support, not in the Git repository: it may contain sensitive values, and concurrent writes need to be prevented.
What interviewers look for
A common scenario is drift: someone edits a managed resource in the cloud console, and it no longer matches the code. Ask whether the edit was intentional before applying. If the change should stay, update the code and review a new plan. If it shouldn't, review how the tool will restore the intended settings.
Be especially careful when a plan says a resource must be replaced rather than updated in place. For a database, explain how you'd assess downtime and protect or migrate the data before proceeding. Reverting a Git commit changes the desired configuration; it doesn't bring back deleted data.