Terraform · Infrastructure as code

Why use infrastructure as code?

Easyinfrastructure as codeautomationidempotencyUpdated Oct 2026
Quiz this track

Short answer

IaC defines infrastructure in versioned files so environments are reproducible, reviewable and recoverable. Changes follow the same review and CI path as application code.

Infrastructure as code turns provisioning into a reviewable artifact. Instead of a sequence of console clicks, the desired state lives in version control, so you can diff changes, review them before they happen, and rebuild an environment from the same source.

hcl
resource "aws_s3_bucket" "logs" {
  bucket = "acme-logs-prod"
}

resource "aws_s3_bucket_versioning" "logs" {
  bucket = aws_s3_bucket.logs.id

  versioning_configuration {
    status = "Enabled"
  }
}
The bucket and its versioning policy are declared together and reviewed as one change.

What teams gain

  • Reproducible environments from the same commit
  • Peer review of security and cost changes before apply
  • Idempotent runs that converge instead of duplicating resources
  • An auditable history of who changed what and why
  • Faster recovery when an environment must be rebuilt

The trade-off is that IaC is software. It needs module boundaries, tests, version pinning and a state strategy. A badly structured repository can be harder to change than the console it replaced, especially when one root module owns hundreds of unrelated resources.

IaC does not remove the need for change management. It moves the decision earlier, into the pull request and the plan output.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What does idempotent mean for infrastructure?
  2. 2How do you review an infrastructure change safely?
  3. 3What are the downsides of managing everything in one configuration?
  4. 4How does IaC help with disaster recovery?

Say it in the interview

I use infrastructure as code so environments are defined in version control and changes can be reviewed before they touch production. Terraform converges to the declared state, which makes runs repeatable and rebuilds realistic. The trade-off is that the repository becomes software, so I invest in module boundaries, pinned versions and CI checks rather than assuming IaC is automatically safer.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.