Plan/Apply Workflow
The operational loop around the code: init, plan, apply, CLI workspaces, targeting, tests and running it all in CI. Interviewers ask how a plan gets reviewed: that separates IaC from a shared laptop.
part ofTerraformread it →on this pageshowhide
explore
- Core Commands and Saved Plans6 questions
- Workspaces5 questions
- Refresh and Drift Handling5 questions
- Targeting, Replace, and Parallelism4 questions
- CI/CD Integration5 questions
- Static Checks in CI4 questions
- Native Test Framework5 questions
- Mock Providers and Overrides5 questions
- Live-Account Testing6 questions
- Terragrunt Wrapper6 questions
- Cost Estimates with Infracost6 questions
questions
page 2 of 2What does the plan file produced by `terraform plan -out=tfplan` actually contain, and why does that make it sensitive?
basics
~20 sA saved plan is an opaque binary archive holding the configuration, a snapshot of prior state and every planned attribute value — including values marked sensitive, which are only masked in the printed output, not removed from the file. Protect it exactly like state.
Why did a team's Infracost job post a cost comment and stay green while a pull request added $4,000 a month, and what would make that cost block the merge?
basics
~20 sInfracost treats a cost increase as information: scan and diff exit non-zero only on errors such as critical diagnostics. Blocking needs a guardrail set to block the pull request, or your own script testing the JSON, plus a required check.
With Infracost, why can a pull request adding a function behind a busy queue show almost no monthly increase while the bill later jumps, and how do you handle it?
basics
~20 sInfracost prices what code declares, and request counts or stored gigabytes are not in the code. Such a component shows a unit price and adds nothing to the total, so supply usage values and read the total as partial.
After `terraform apply -refresh-only` records a colleague's console change into Terraform state, what does the very next plain `terraform plan` propose, and why?
basics
~20 sIt proposes changing the resource back to whatever the configuration says. Refresh-only updates state, never the .tf files, so the plan now compares an accurate state against an unchanged config and sees a difference it intends to correct.
How would you run a scheduled Terraform drift-detection job in CI, and how should the job decide whether to raise an alert?
basics
~20 sRun terraform init and a non-interactive plan on a schedule against the deployed branch, and branch on -detailed-exitcode: 0 means no changes, 2 means the world differs from code, 1 means the run itself failed. Alert on 2, page on repeated 1.
After an incident you fixed production with `terraform apply -target=module.db`. The next untargeted `terraform plan` proposes changes to resources nobody edited. What explains that, and how do you handle the plan?
basics
~20 sA targeted apply evaluates and refreshes only the targeted subgraph, so the first untargeted plan afterwards shows the catch-up work: dependents that never picked up new attribute values, stale outputs, and real-world drift no run had refreshed since.
A Terragrunt plan for `live/dev/us-east-1/app` shows `vpc-mock` as its VPC ID because `../vpc` was never applied. What is happening, and how do you stop that value reaching a real apply?
basics
~20 sThe dependency block found no outputs in the unapplied vpc unit, so Terragrunt substituted mock_outputs. With no allow-list those mocks work for every command, so set mock_outputs_allowed_terraform_commands and never apply a saved plan built on mocks.
A Terratest test of a VPC module fails its endpoint check right after apply but passes on rerun: where do retries belong, and what should not be retried?
basics
~10 sRetry at two layers: terraform.WithDefaultRetryableErrors re-runs a Terraform command on listed transient errors, and http_helper or retry.DoWithRetryContext polls the live check. Deterministic failures should stop at once, and retries must fit the test timeout.
Under Terraform's `mock_provider`, why does a format-checking validation reject a computed ARN in a credential-free CI job running a module's `.tftest.hcl` tests, and how do you fix it?
basics
~20 sTerraform's mock_provider knows an attribute's type, not its format, so a computed arn arrives as a random 8-character string and fails the regex at apply. Set an ARN-shaped value with mock_resource defaults or override_resource on the producing resource.
Why do teams run Checkov or Trivy against `terraform show -json` plan output instead of the raw HCL, and what does that cost them?
basics
~20 sPlan JSON contains resolved values, so a scanner sees the attribute a resource will really have instead of an unresolved var or module reference. The cost is that it needs init, credentials and a successful plan, so it runs late and can never be a pre-commit check.
In a Terraform `.tftest.hcl` file using a setup helper module, how do state keys decide which `run` blocks can run in parallel and what cleanup destroys first?
basics
~20 sTerraform test files keep one in-memory state per state key: by default the main configuration and each helper module source. Run blocks sharing a key never run concurrently, and cleanup destroys the most recently updated state first.
A Terraform CI job applied against the default workspace instead of `staging`. How does Terraform decide which CLI workspace is active, and how do you make that deterministic in a pipeline?
basics
~20 sTerraform reads the active workspace from .terraform/environment in the working directory. A fresh CI checkout has no such file, so it silently uses default. Make it explicit with TF_WORKSPACE or a terraform workspace select step after init.
When pull requests show an Infracost monthly cost diff and leadership wants large increases blocked, who should own the threshold, and should cost ever block a merge?
basics
~20 sDefault to a visible comment routed to an accountable owner, not a veto: the estimate misses usage, and engineers cannot usually approve spending alone. The budget holder owns the threshold; reserve blocking for high-confidence limits with a fast, recorded override.
Your team runs about forty Terraform root modules with hand-copied backend and provider blocks. How would you decide whether to adopt Terragrunt, and what lock-in would you accept?
basics
~20 sAdopt Terragrunt when repetition and ordering across many similar roots cost more than a second tool; keep plain root modules and CI when roots are few or independent. The lock-in sits in orchestration and configuration, not in state.
Your organisation's Terratest suites apply real infrastructure into sandbox accounts: who should own those accounts and their bill, and what standing rules would you set?
basics
~20 sA common answer: a platform team owns the sandbox accounts, guardrails and sweep, while each team writing tests sees and answers for its share of the bill. Standing rules cover isolation, naming, budgets, mandatory cleanup and leak reporting.
You own a shared Terraform network module used by many teams: what do you require of its `terraform test` suite before you tag a release, and why?
basics
~20 sFor a shared Terraform module's test suite, require a failure case for each promised custom condition, plan-only logic tests and at least one real apply in a dedicated account that cleans up after itself, scaled to blast radius and cost.
What does `terraform plan -detailed-exitcode` return, and how would you use it in a script?
basics
~20 sWith -detailed-exitcode, terraform plan exits 0 when there are no changes, 1 on error, and 2 when the plan succeeded and changes are pending. Scripts use it to tell an empty diff apart from a real one without parsing output.
On Infracost CLI 2.x, what happens to an old script running `infracost breakdown --path . --format json --out-file base.json` and `infracost comment github`?
basics
~20 sOn Infracost CLI 2.x, breakdown warns and runs scan, keeping only the path and silently dropping the format and output flags, so no JSON file appears. The comment command fails outright and points to infracost ci setup.
With Infracost, when would you commit an `infracost.yml` instead of relying on autodetection, and what does the file pin down?
basics
~20 sCommit an infracost.yml when detection's project list or names are not what you want: it pins each project's path, name and type, plus a usage file. Names matter because diffs, guardrail costs and usage filters match projects by name.
In Terragrunt, how do implicit stacks differ from explicit stacks defined in `terragrunt.stack.hcl`, and when is the generated form worth it?
basics
~20 sAn implicit Terragrunt stack is a directory tree of hand-written units. An explicit stack is a terragrunt.stack.hcl blueprint that generates its units into .terragrunt-stack. Explicit pays off when the same set of units repeats across environments.
With Terratest's `test_structure` package, how do you re-run only the validation step of a slow test without redeploying the module each time?
basics
~10 sWrap deploy, validate and teardown in test_structure.RunTestStage, then set SKIP_<stage> for each stage to skip. Save options to disk in the deploy stage and load them later, because a skipped stage's function never runs.
How do you correctly retire an ephemeral Terraform CLI workspace, and what happens if you run `terraform workspace delete` while its state still tracks resources?
basics
~20 sDestroy inside the workspace first, then select another workspace and delete it. Terraform refuses to delete a workspace whose state still tracks resources unless you pass -force, which discards the state and orphans the real infrastructure.
A large `terraform apply` keeps failing partway through with rate-limit errors from the cloud provider's API. What does Terraform's `-parallelism` option control, and how would you use it here?
basics
~20 sTerraform's -parallelism sets how many resource operations one run performs concurrently while walking the dependency graph, defaulting to 10. Lowering it thins the burst of API calls the run makes, which is the fastest way to get a throttled apply through.
What does declaring `mock_provider "aws"` in a Terraform test file change about how the tests execute, and what stops being tested?
basics
~20 sA mock_provider block replaces the real provider, so Terraform walks the full plan and apply graph while generated values stand in for computed attributes. Nothing is created, no credentials are needed, and tests run in seconds — but no API ever validates the request.
When would you run Terraform through a purpose-built run service such as Atlantis or HCP Terraform instead of hand-written plan and apply jobs in your existing CI system?
basics
~20 sAdopt a run service when the number of Terraform repositories makes hand-rolled jobs a maintenance burden, and when you want cloud credentials, state, run history and approvals owned by one system instead of scattered across CI configurations.
You own hundreds of Terraform root modules, and refresh on every plan is now saturating provider API rate limits. How do you keep refresh and drift detection affordable?
basics
~20 sTreat refresh cost as proportional to resources per state and runs per hour, then attack both: keep root modules small, tier how often each is fully refreshed, stagger schedules so runs do not collide, and reserve unrefreshed plans for cheap feedback rather than for gated applies.
showing 31–57 of 57