Skip to content

002 · Domain 3: Infrastructure Lifecycle and Operations · 22% of the exam

Task 3.2: Plan changes to infrastructure

The plan as a review artifact: planning modes, -refresh=false, -target and -exclude, saved plan files, -detailed-exitcode, and reading what a plan proposes to replace.

Study it

  • Plans as review artifacts: modes, targeting, exclusion and saved plans

    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 1

During an incident an engineer runs terraform plan -target=aws_lb_listener.https on a large configuration. The listener references a target group and a certificate; a monitoring dashboard references the listener. Which objects does the plan consider?

  1. AThe listener and the dashboard that references it, but none of the objects the listener depends on
  2. BOnly the listener, with every other object ignored
  3. CThe listener plus the target group and certificate it depends on, but not the dashboard
  4. DEvery object in the configuration, with only the listener, target group and certificate refreshed
Show the answer and why
  • AThe listener and the dashboard that references it, but none of the objects the listener depends on

    Incorrect

    Targeting follows dependencies of the targeted object, not objects that depend on it.

  • BOnly the listener, with every other object ignored

    Incorrect

    The selection always grows to include the objects the targeted instances depend on.

  • CThe listener plus the target group and certificate it depends on, but not the dashboard

    Correct

    Targeting selects the given instances and extends the selection to everything they depend on directly or indirectly.

  • DEvery object in the configuration, with only the listener, target group and certificate refreshed

    Incorrect

    Objects outside the targeted set and its dependencies are left out of the plan entirely.

-target is for exceptional situations such as recovering from mistakes; routine use risks undetected drift. Splitting very large configurations is the recommended long-term answer.

Question 2 · choose 2

A wrapper script builds terraform plan command lines from user options. Which two combinations does Terraform reject? (Choose TWO.)

  1. Aterraform plan -refresh=false -target=aws_instance.web
  2. Bterraform plan -refresh-only -refresh=false
  3. Cterraform plan -replace=aws_instance.web -replace=aws_instance.api
  4. Dterraform plan -destroy -replace=aws_instance.web
  5. Eterraform plan -destroy -out=teardown.tfplan
Show the answer and why
  • Aterraform plan -refresh=false -target=aws_instance.web

    Incorrect

    Skipping refresh and targeting are both normal planning options and can be used together.

  • Bterraform plan -refresh-only -refresh=false

    Correct

    -refresh=false cannot be used in refresh-only mode, because it would disable the whole purpose of the plan.

  • Cterraform plan -replace=aws_instance.web -replace=aws_instance.api

    Incorrect

    -replace can be given several times to replace several objects in one plan.

  • Dterraform plan -destroy -replace=aws_instance.web

    Correct

    -replace cannot be combined with -destroy.

  • Eterraform plan -destroy -out=teardown.tfplan

    Incorrect

    A destroy-mode plan can be saved to a file and applied later like any other saved plan.

Planning modes are mutually exclusive, -refresh=false is meaningless in refresh-only mode, and -replace does not combine with destroy mode. Other planning options can be mixed and repeated.

Question 3 · choose 1

A pipeline runs terraform plan -var "length = 2" and fails. What is wrong?

  1. A-var accepts only string values, not numbers
  2. BThe variable must also be set in terraform.tfvars
  3. CDouble quotes are not allowed around -var values
  4. DThe spaces around the equals sign
Show the answer and why
  • A-var accepts only string values, not numbers

    Incorrect

    -var values are parsed as Terraform expressions, so numbers are fine.

  • BThe variable must also be set in terraform.tfvars

    Incorrect

    A -var value does not need a matching tfvars entry.

  • CDouble quotes are not allowed around -var values

    Incorrect

    Double quotes are the recommended quoting on Windows Command Prompt.

  • DThe spaces around the equals sign

    Correct

    Terraform errors if you include a space before or after the equals sign, so write -var "length=2".

Keep NAME=VALUE together as one shell argument, with no spaces around the equals sign.

Question 4 · choose 1

A pipeline wrapper converts each saved plan with terraform show -json and must decide whether to send the plan to an approver for applying. Which field does the JSON output format tell wrapping automation to use as its primary condition?

  1. Aerrored, which must be false
  2. Bresource_changes, which must not be empty
  3. Capplyable, which must be true
  4. Dformat_version, which must match the CLI
Show the answer and why
  • Aerrored, which must be false

    Incorrect

    errored says whether planning failed; the documentation names a different flag as the primary condition for applying.

  • Bresource_changes, which must not be empty

    Incorrect

    Counting resource changes is not the documented condition, and it misses plans whose only changes are to outputs.

  • Capplyable, which must be true

    Correct

    applyable indicates that it would make sense for wrapping automation to try to apply the plan, and automation should use it as its primary condition.

  • Dformat_version, which must match the CLI

    Incorrect

    format_version describes the JSON format, not whether the plan can be applied.

The exact definition of applyable may change in later Terraform versions, which is why automation should rely on the flag instead of rebuilding the logic from other fields.

Question 5 · choose 1

An engineer runs terraform plan -target=module.network. The module calls another module, subnets. What does the plan include?

  1. AAll resources in module.network and in its child modules
  2. BOnly resources declared directly in module.network
  3. COnly the module's outputs, recalculated without resource changes
  4. DNothing: -target accepts resource addresses, not modules
Show the answer and why
  • AAll resources in module.network and in its child modules

    Correct

    A module address selects all instances of all resources in that module instance and all of its child module instances.

  • BOnly resources declared directly in module.network

    Incorrect

    Targeting a module includes its child module instances too.

  • COnly the module's outputs, recalculated without resource changes

    Incorrect

    Targeting selects resources, not just outputs.

  • DNothing: -target accepts resource addresses, not modules

    Incorrect

    A module instance address is a valid target.

Targeting is for exceptional situations such as recovery; routine work should plan the whole configuration.

Question 6 · choose 1

A CI job runs terraform plan -compact-warnings. In which case does the output still include the full text of the warnings?

  1. AWhen TF_LOG is set to WARN for the job
  2. BWhen at least one error is also reported
  3. CWhen the plan is saved to a file with -out
  4. DWhen -no-color is set on the same command
Show the answer and why
  • AWhen TF_LOG is set to WARN for the job

    Incorrect

    Logging levels control the debug log, not plan diagnostics.

  • BWhen at least one error is also reported

    Correct

    The option shows only summaries unless at least one error accompanies the warnings, where the text might help explain the error.

  • CWhen the plan is saved to a file with -out

    Incorrect

    Saving the plan does not change how warnings are printed.

  • DWhen -no-color is set on the same command

    Incorrect

    -no-color removes color codes only.

Compact warnings keep CI logs short without hiding context that matters for a failure.

Practice domain 3 →Practice all domains →