Terraform interview question · Most asked

What does terraform plan -target do, and why is it risky?

Definition Asked in DevOps Engineer · Cloud Engineer · Site Reliability Engineer (SRE) interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

-target tells Terraform to plan and apply only the named resource (and its dependencies). It is meant for exceptional recovery situations, not normal workflow, because it leaves state partially updated and can cause drift between what Terraform knows and what exists.

Longer Answer

When you run terraform plan -target=aws_instance.web, Terraform:

  1. Refreshes only the targeted resource and its upstream dependencies.
  2. Computes a plan that ignores everything else in the configuration.
  3. On apply, writes state only for the resources it touched.

Legitimate uses:

  • Unblocking a stuck apply: one resource keeps failing and blocks fifty others. Target the failing resource to fix it, then run a full plan to reconcile.
  • Bootstrapping circular dependencies: rare cases where resource A needs to exist before resource B can be planned, but both are in the same configuration.
  • Emergency hotfix: production is down and you need to change one security group rule without waiting for a full plan across hundreds of resources.

Why it's risky:

  • Partial state: other resources may now be out of sync. A subsequent full plan may show unexpected changes because Terraform didn't refresh everything.
  • Skipped validation: resources that depend on the target but aren't targeted themselves are not validated — they may fail on the next full apply.
  • Habit formation: teams that use -target routinely are usually avoiding slow plans, which is a symptom of needing to split the state, not target individual resources.

Terraform itself prints a warning: "Resource targeting is in effect" and "This is not a normal workflow." Always follow a targeted apply with a full terraform plan to verify consistency.

Key Points

  • -target plans only the named resource and its dependencies, ignoring everything else
  • Leaves state partially updated — always follow with a full plan to reconcile
  • Legitimate for emergency fixes and unblocking stuck applies, not for routine use
  • Routine -target use usually means the state needs to be split, not targeted

Explanation

What interviewers look for

Look for awareness that -target is a recovery tool, not a workflow optimisation. Weak answers describe it as a way to speed up applies. Strong answers mention the partial state risk and the need for a reconciliation plan afterwards.

More Terraform questions

← All Terraform questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake