LevelUpWith

Explore / HashiCorp Certified: Terraform Associate (004) Exam Prep / Lesson 2

Lesson 2: Advantages of IaC Patterns

[1 Infrastructure as Code (IaC) with Terraform — 1b Describe the advantages of IaC patterns] Explains why teams adopt IaC: configuration that is versioned, reviewable, repeatable and reusable, with a plan to read before anything changes.

Free to read, no account needed. Part of HashiCorp Certified: Terraform Associate (004) Exam Prep.

By the end of this level you'll be able to

  • Match IaC advantages (version control, repeatability, automation, review before change, reuse) to the operational problem each one solves
  • Explain idempotence by predicting what a second terraform apply reports when nothing has changed
  • Pick the best IaC benefit in a scenario question and say why the other options are weaker

Why teams bother with IaC

In level 1 you saw what infrastructure as code is: you describe infrastructure in files and a tool makes reality match. Objective 1b asks the next question: why is that better than clicking through a console or running ad-hoc scripts?

You have probably lived the problems already. Someone resized a server at 2 a.m. and nobody knows who. Staging "should be the same as production" but isn't. A new environment takes a week because the steps live in one person's head. Each IaC advantage is the fix for one of these.

Five advantages, five problems

Advantage The problem it solves
Version control "Who changed this, when, and why?" Configuration is a text file, so it goes in Git: history, blame, and a known-good version to go back to.
Review before change "I didn't know that would delete the database." Terraform creates an execution plan describing what it will create, update or destroy, and prompts for approval before modifying anything.
Repeatability "Staging doesn't match production." The same configuration produces the same infrastructure every time, with no forgotten steps.
Automation "Provisioning takes days and a ticket queue." The tool makes the API calls and works out the order of operations for you.
Reuse "Every team builds its own slightly different network." Terraform supports reusable components called modules, so you standardise once and share.

HashiCorp's own summary is that you can version, reuse and share configuration files, then use one consistent workflow across the whole lifecycle. On the exam, the skill is matching the benefit to the pain.

Walkthrough: see the benefits at the terminal

Here is a deliberately tiny configuration. Don't worry about the block syntax yet; it just says "a file with this content should exist".

# main.tf: the desired end state, written as text
resource "local_file" "motd" {
  filename = "motd.txt"
  content  = "Managed by Terraform\n"
}

Version control. Because it is a file, the normal software workflow applies:

git add main.tf
git commit -m "Add message-of-the-day file"   # who, when, why, recorded for good

A teammate can now review the change in a pull request, exactly as they would application code.

Review before change. Ask Terraform what it would do:

$ terraform plan

Terraform will perform the following actions:

  # local_file.motd will be created
  + resource "local_file" "motd" {
      + content  = "Managed by Terraform\n"
      + filename = "motd.txt"
      ...                                  # output trimmed
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Nothing has changed yet. + means create, ~ means update in place, - means destroy. The summary line is the one to read every time: an unexpected "1 to destroy" is your cue to stop.

Automation. terraform apply shows the same plan, waits for you to type yes, then does the work:

$ terraform apply
...
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Idempotence: run it again, nothing happens

Now run the exact same command a second time without touching anything:

$ terraform apply
local_file.motd: Refreshing state...

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

That is idempotence: applying the same configuration once or ten times leaves you with the same result. Terraform's language is declarative, so it describes the end state rather than the steps. When the end state already exists, there is nothing to do.

Compare a naive script containing create_server web-1. Run it twice and you get either a second server or an error. With Terraform, a re-run is safe, which is exactly what makes it sensible to put in a pipeline.

Gotcha: "No changes" is only guaranteed when neither the configuration nor the real infrastructure has changed. If someone edits a resource by hand, the next plan will propose putting it back. That is a feature, and a later level covers it properly.

Reuse and repeatability together

Once the configuration works, the same files can build dev, staging and production. Later you will package common pieces as modules so that ten teams use one reviewed network definition rather than ten home-made ones. The benefit is consistency, and less code to write is a bonus on top.

Honest trade-offs

  • IaC does not prevent mistakes; it makes them visible. A plan nobody reads protects nobody.
  • Discipline is required. Manual console changes undermine the "files are the source of truth" promise.
  • It is slower for a one-off. Writing code beats clicking only when you need the thing again, need it reviewed, or need a record. In production that is almost always.

What the exam asks about this

Expect short scenario questions: a team has a problem, and you pick the IaC benefit that addresses it. Tips:

  • Find the key symptom. "No record of who changed it" points to version control. "Environments differ" points to repeatability. "Surprised by a deletion" points to reviewing the execution plan.
  • Distractors are often true statements that answer a different problem. Pick the option that fixes this problem.
  • Be suspicious of absolutes. IaC does not "eliminate all errors" or "remove the need for review".
  • Know what a second terraform apply reports when nothing changed: no changes, 0 added, 0 changed, 0 destroyed.

Key takeaways

  • Configuration is text, so it can be versioned, reviewed, shared and rolled back like any code.
  • Terraform shows an execution plan and asks for approval before modifying infrastructure.
  • The same configuration gives the same result: repeatable environments, with no forgotten manual steps.
  • Idempotence: re-applying an unchanged configuration against unchanged infrastructure reports no changes.
  • Modules let you reuse and standardise infrastructure patterns across teams.
  • In scenario questions, match the benefit to the specific operational problem described.

A 6-question knowledge check follows this lesson in the app, free and without an account.

Keep going: levels 3 and 4 are free

Create a free account to open the next two levels, save your progress and pick up where you left off. No card needed.

Next: Level 3, Multi-Cloud, Hybrid Cloud and Service-Agnostic Workflows.

Create a free account →See the whole course

More like this

  • GitHub Copilot (GH-300) Exam Prep

    Learn GitHub Copilot hands-on in the editor, in the CLI and on github.com, and work through every skill in the GH-300 study guide (skills measured as of August…

    Exam prep · GH-300 · Software & Engineering · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com

  • Scaling Apps Beyond the Chat Window: Part 3, Mobile Apps, Games and Growth

    Turn your first live app into a real product. Learn to choose between web and app store apps, publish a browser game, take payments safely, run and monitor a l…

    Course · Software · Software & Engineering · Capable · 24 levels · 4 free · Professionally curated by levelupwith.com

  • Scaling Apps Beyond the Chat Window: Part 2, Online, Secure and AI-Powered

    Take one small app from your GitHub repository to a public web address. You will host it on Vercel and give it a Supabase database, sign-in and file storage, w…

    Course · Software · Software & Engineering · Capable · 16 levels · 4 free · Professionally curated by levelupwith.com

  • Scaling Apps Beyond the Chat Window: Part 1, From Prompt to Project

    Move an app you built in an AI chat onto your own computer and work on it step by step with a coding agent. Save your work with Git, keep secrets out of your c…

    Course · Software · Software & Engineering · Capable · 19 levels · 4 free · Professionally curated by levelupwith.com

  • Right Chip, Right Job: CPUs, GPUs, TPUs and Beyond

    Profile a workload, place it on a roofline and pick the processor that actually suits it, whether CPU, GPU, TPU, ASIC, inference chip, NPU, FPGA or DPU. You wi…

    Beyond the Obvious · Software & Engineering · Expert · 61 levels · 4 free · Professionally curated by levelupwith.com

  • Build Your First Website with HTML and CSS

    Start from a blank file and build a real, accessible personal or small-business website that works on phones. Each level adds to the same site, covering semant…

    Course · Software · Software & Engineering · Capable · 18 levels · 4 free · Professionally curated by levelupwith.com