Skip to content

004 · Domain 1: Infrastructure as Code (IaC) with Terraform · 12% of the exam

Task 1.2: Describe the advantages of IaC patterns

Why teams adopt it: changes reviewed like code, a plan before every change, repeatable environments, reusable modules, an audit trail in version control, fewer manual mistakes, and drift you can see.

Study it

  • Why IaC: version history, review, plans, repeatable and disposable environments

    Lesson coming

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 2

After an outage, an auditor asks who changed a load balancer's listener port, when, and why. The team manages the load balancer with Terraform and keeps its configuration in Git, with changes merged through reviewed pull requests. Which two sources answer the auditor? (Choose TWO.)

  1. AThe state file keeps a full history of every attribute value and the user who set it
  2. BThe configuration's commit history shows the change, its author, date and reason
  3. CThe provider writes the Terraform user name into a tag on every resource it changes
  4. DTerraform keeps a log of every plan in the .terraform directory for later audits
  5. EThe pull request that introduced the change, with its review and approval
Show the answer and why
  • AThe state file keeps a full history of every attribute value and the user who set it

    Incorrect

    State records the current mapping to real objects; it is not an authorship log of configuration changes.

  • BThe configuration's commit history shows the change, its author, date and reason

    Correct

    Because the configuration is a file you can version, version control keeps who changed it, when, and the reason in the commit and its review.

  • CThe provider writes the Terraform user name into a tag on every resource it changes

    Incorrect

    Providers do not add authorship tags by themselves; any tags come from the configuration.

  • DTerraform keeps a log of every plan in the .terraform directory for later audits

    Incorrect

    The .terraform directory holds the working directory's providers, modules and backend settings, not an audit trail.

  • EThe pull request that introduced the change, with its review and approval

    Correct

    Teams review configuration changes alongside pull requests, so the pull request records who reviewed and approved the change.

Configuration files in version control give infrastructure the same history as application code: every change has an author, a time, a reason and, usually, a review.

Question 2 · choose 1

A team that changes firewall rules by hand has twice deleted a rule that production depended on. They move the rules to Terraform. Which Terraform behavior most directly prevents this kind of surprise?

  1. ATerraform refuses to delete any resource that another resource depends on
  2. BTerraform shows a plan of every change and waits for approval before making it
  3. CTerraform keeps a backup copy of every deleted firewall rule so it can be restored later
  4. DTerraform locks each firewall rule so nobody can change it outside Terraform
Show the answer and why
  • ATerraform refuses to delete any resource that another resource depends on

    Incorrect

    Terraform orders deletions by dependency but will still delete what the plan proposes; dependencies do not make a resource undeletable.

  • BTerraform shows a plan of every change and waits for approval before making it

    Correct

    Terraform generates a plan and prompts for approval before modifying infrastructure, so an unintended deletion is visible before it happens.

  • CTerraform keeps a backup copy of every deleted firewall rule so it can be restored later

    Incorrect

    Terraform does not back up remote objects it destroys. Only the state file has a local backup.

  • DTerraform locks each firewall rule so nobody can change it outside Terraform

    Incorrect

    Terraform cannot stop changes made outside it; state locking only stops two Terraform runs from writing the same state.

The plan is the safety net of the workflow: every proposed change, including each deletion, is shown for review before apply makes it.

Question 3 · choose 1

A company opens a new region and needs the same networking, load balancers and instance groups it already runs in two other regions, all built from Terraform. Compared with rebuilding by hand, what is the main gain?

  1. ATerraform copies the running resources from the other regions without needing configuration
  2. BThe existing configuration, applied with new inputs, builds the region the same way
  3. CThe new region skips planning because the configuration was already applied elsewhere
  4. DThe new region needs no provider configuration because the providers are already installed
Show the answer and why
  • ATerraform copies the running resources from the other regions without needing configuration

    Incorrect

    Terraform creates what the configuration describes; it does not clone live resources.

  • BThe existing configuration, applied with new inputs, builds the region the same way

    Correct

    IaC lets you build and change infrastructure in a consistent, repeatable way by reusing configurations.

  • CThe new region skips planning because the configuration was already applied elsewhere

    Incorrect

    Each environment gets its own plan against its own state.

  • DThe new region needs no provider configuration because the providers are already installed

    Incorrect

    Installed providers still need configuration, for example the new region.

Repeatability is speed: once the infrastructure is code, building it again is an apply, not a project.

Question 4 · choose 1

A small team needs a production-grade virtual network with public and private subnets, routing and NAT, and has little time. Which Terraform advantage helps most?

  1. AUsing a published module from the Terraform Registry
  2. BUsing terraform console to generate the network resources interactively
  3. CCopying another company's state file that already contains a network
  4. DAsking the provider to choose sensible subnets during terraform init
Show the answer and why
  • AUsing a published module from the Terraform Registry

    Correct

    Publicly available modules on the Terraform Registry package collections of resources, saving time and encouraging best practices.

  • BUsing terraform console to generate the network resources interactively

    Incorrect

    console evaluates expressions; it does not write configuration.

  • CCopying another company's state file that already contains a network

    Incorrect

    Someone else's state refers to their objects and would not create a network for this team.

  • DAsking the provider to choose sensible subnets during terraform init

    Incorrect

    init installs providers and modules; it does not design networks.

Modules are reusable infrastructure. The public registry means many common patterns are already written and versioned.

Question 5 · choose 1

Every hand-built server in a fleet has slightly different settings because each was configured by a different person. What does defining the fleet in Terraform change?

  1. ATerraform inspects existing hand-built servers and standardizes them without configuration
  2. BTerraform prevents anyone from logging in to a server it created
  3. CTerraform guarantees that the application on each server has no configuration bugs
  4. DEach server comes from the same definition, so settings no longer vary by builder
Show the answer and why
  • ATerraform inspects existing hand-built servers and standardizes them without configuration

    Incorrect

    Terraform changes what its configuration describes; it does not standardize unmanaged servers on its own.

  • BTerraform prevents anyone from logging in to a server it created

    Incorrect

    Access to servers is governed by the platform's access controls, not by Terraform.

  • CTerraform guarantees that the application on each server has no configuration bugs

    Incorrect

    Terraform provisions infrastructure; it cannot vouch for application settings it does not manage.

  • DEach server comes from the same definition, so settings no longer vary by builder

    Correct

    IaC builds infrastructure in a safe, consistent and repeatable way from configuration you can reuse, which removes person-to-person variation.

Consistency is a direct product of IaC: one definition, many identical copies, and no step left to memory.

Question 6 · choose 1

A module team wants to catch breaking changes to its modules automatically before releasing a new version, the way application teams run unit tests. Which capability does Terraform provide for this?

  1. AThe terraform validate command, which creates temporary resources to test the module
  2. Bterraform test, which runs test files with run blocks and assertions
  3. CThe terraform graph command, which fails when a module has a breaking change
  4. DThe terraform fmt -check command, which compares the module with its previous version
Show the answer and why
  • AThe terraform validate command, which creates temporary resources to test the module

    Incorrect

    validate never creates resources or contacts remote services.

  • Bterraform test, which runs test files with run blocks and assertions

    Correct

    terraform test runs .tftest.hcl files with run blocks and assertions, so infrastructure code can be tested like application code.

  • CThe terraform graph command, which fails when a module has a breaking change

    Incorrect

    graph prints the dependency graph; it does not check behavior.

  • DThe terraform fmt -check command, which compares the module with its previous version

    Incorrect

    fmt -check only reports formatting differences.

Treating infrastructure as code includes testing it. terraform test brings automated assertions to modules.

Question 7 · choose 1

Five engineers start working on the same Terraform configuration, and each keeps state on a laptop. Which change lets them collaborate safely?

  1. AEmail the newest state file to the team after each apply
  2. BGive each engineer a separate copy of the configuration with different resource names
  3. CStore state remotely, for example in HCP Terraform, with locking
  4. DCommit terraform.tfstate to Git after every apply
Show the answer and why
  • AEmail the newest state file to the team after each apply

    Incorrect

    Passing state files around invites lost updates and leaks of the secrets inside them.

  • BGive each engineer a separate copy of the configuration with different resource names

    Incorrect

    Copies with different names would create duplicate infrastructure, not shared management.

  • CStore state remotely, for example in HCP Terraform, with locking

    Correct

    Remote state lets teams share state securely, and HCP Terraform provides a stable run environment that prevents race conditions between people.

  • DCommit terraform.tfstate to Git after every apply

    Incorrect

    State can contain secrets in plain text, and a file in Git gives no state locking between runs, so it is not a safe shared store.

Collaboration needs one shared state with locking; remote state backends and HCP Terraform provide it.

Practise domain 1 →Practise all domains →