TF-Associate-004 domain - 19% of the exam

Core Terraform workflow

Core Terraform workflow is 19% of the TF-Associate-004 exam. These are the objectives it covers, each with practice questions, with every answer explained.

The domain in numbers

57
Practice questions
7
Objectives
32
Easy
25
Medium

Where people go wrong

  • Treating plan as the step that changes infrastructure

    The wrong answers credit terraform plan with work that only apply does: provisioning new resources, destroying a resource listed in the summary, or performing a rollback. Plan compares the configuration against the current state and reports proposed actions. It creates, updates and destroys nothing, so a destroy line in its output is a proposal. Real infrastructure changes only when terraform apply runs, whether it plans first or consumes a saved plan file.

    See it in a sample question
  • Expecting validate to contact the provider or detect drift

    The wrong answers give terraform validate the reach of plan: refreshing real resources, reading state, detecting console changes, needing credentials or calling provider APIs. Validate runs offline against the configuration and the installed provider schemas. It catches bad syntax, references to nonexistent attributes and arguments given the wrong value type. Drift, permission errors and rate limits only appear when plan or apply calls the provider, which is why validate succeeds on a machine with no cloud credentials.

    See it in a sample question
  • Expecting plan, apply or validate to install providers

    The wrong answers reach for another command when a provider plugin is missing: validate, apply, a refresh-only apply, terraform get, providers lock, or deleting the lock file. None of them installs providers. A freshly cloned directory, or one where a new required_providers entry has been added, has no plugin installed, so terraform init must run first. Init downloads the declared providers into the working directory and records them in the dependency lock file, so it is re-run whenever a provider is added.

    See it in a sample question
  • Mistaking other flags for -auto-approve

    To run apply or destroy unattended, the wrong answers pick a flag that sounds related: -input=false, disabling the state lock, skipping the refresh, or adding -auto-approve to plan. The -input=false flag only stops prompting for missing variables, so with no approval given the run fails instead of proceeding. The state lock governs concurrency and the refresh governs reconciliation. Only -auto-approve skips the yes prompt, and plan does not accept it.

    See it in a sample question
  • Expecting fmt flags to stop it writing files

    A CI job that must fail on badly formatted files without editing them needs fmt -check, which reports non-conforming files and returns a non-zero exit code. The wrong answers choose -recursive, -json or -write=true, all of which still rewrite files. The -write=true form is the default behaviour and does not fail on unformatted input. Validate cannot replace -check either, because it checks configuration correctness, not formatting style.

    See it in a sample question

Objectives in this domain

What to study

The official documents this domain's practice questions cite most.

Sample questions from this domain

Free sampleCore Terraform workfloweasy

Which statement most accurately describes what running terraform plan does to your managed infrastructure?

  • AIt applies additions immediately but defers deletions until the next apply
  • BIt provisions any new resources while leaving existing resources untouched
  • CIt previews the proposed changes without making any changes to infrastructure Correct
  • DIt rolls back the most recent apply if drift is detected
The plan step previews proposed changes and never modifies real infrastructure itself. Plan is a read-and-compare step that produces a preview of intended actions, so it reports what would change but leaves all real resources exactly as they are.

Why A is wrong: This is tempting because plans distinguish additions from deletions, but plan enacts neither; it only reports both as proposed actions.

Why B is wrong: Plan does list new resources it intends to add, but it does not provision them; provisioning happens only during apply.

Why C is correct: Plan compares desired configuration against current state and shows the actions Terraform would take, without creating, updating, or deleting anything.

Why D is wrong: Plan does surface drift between configuration and reality, but it never reverts a prior apply or performs any rollback of its own.

Free sampleCore Terraform workfloweasy

A colleague changed an EC2 instance type directly in the AWS console, and the running configuration still lists the original type. A practitioner wants to know whether terraform validate will detect this difference between the configuration and the real infrastructure. What is the correct answer?

  • AYes, because validate refreshes the state against the provider and reports any attribute that differs from the configuration.
  • BYes, but only when validate is run with the -refresh-only flag so it compares state to the real instance.
  • CNo, because validate only checks the configuration itself and does not read state or query the provider to detect drift. Correct
  • DNo, because validate checks only for provider credentials and stops before reaching the resource definitions.
terraform validate cannot detect drift because it never reads state or queries the provider; use plan for that. Drift is a difference between the configuration and the real resources recorded in state. Detecting it requires refreshing state against the provider, which only plan and apply do. validate works solely on local configuration, so it stays blind to drift.

Why A is wrong: Tempting because it mirrors what plan does, but validate performs no refresh and reads no state, so it cannot compare against real resources.

Why B is wrong: Tempting because -refresh-only is a real mode, but it belongs to plan and apply, not validate, which accepts no such flag.

Why C is correct: Correct: validate never contacts the provider or refreshes state, so real-world drift is invisible to it; detecting drift is the job of plan.

Why D is wrong: Tempting because validate does run without credentials, but the reason is wrong: validate fully checks the resource definitions and simply never inspects real infrastructure.

Free sampleCore Terraform workfloweasy

A practitioner has just written a new configuration in an empty directory and runs terraform plan straight away. The command fails before producing any plan, complaining about an uninitialised working directory. Which step of the workflow did they skip?

$ terraform plan
Error: Initialization required. Please see the error message above.
$
  • AThey skipped terraform apply, which must run once to register the providers before a plan works
  • BThey skipped terraform init, which installs the required providers and prepares the working directory Correct
  • CThey skipped terraform fmt, which must format the files before Terraform can read them
  • DThey skipped terraform validate, which initialises the backend as a side effect of checking syntax
terraform init prepares the working directory and installs providers before plan or apply can run. A working directory must be initialised so Terraform can install the providers and modules the configuration references; until terraform init has run, plan and apply have no provider plugins to evaluate resources against and fail early.

Why A is wrong: Apply comes after plan, not before it, and cannot run on an uninitialised directory either, so it is not the missing prerequisite.

Why B is correct: Init sits at the start of the workflow and downloads providers and modules into the directory, and plan cannot proceed until it has run.

Why C is wrong: fmt only rewrites configuration to canonical style and is entirely optional; unformatted files still parse and plan correctly.

Why D is wrong: validate checks configuration consistency but does not initialise the directory or install providers, and it also requires init to have run first.

Free sampleCore Terraform workflowmedium

A CI pipeline runs Terraform non-interactively and must apply an already-reviewed change without any human at a keyboard to confirm the prompt. Which single command lets the apply proceed unattended while still executing the changes?

# runs inside an automated CI job, no TTY attached
  • ARun 'terraform apply -auto-approve' so Terraform skips the interactive prompt and applies the change. Correct
  • BRun 'terraform plan -auto-approve' so the plan step approves itself for the later apply.
  • CRun 'terraform apply -input=false' so Terraform treats the confirmation as automatically granted.
  • DRun 'terraform apply -lock=false' so the run does not stop to wait for operator confirmation.
The -auto-approve flag on terraform apply skips the interactive confirmation so changes apply unattended. In automation Terraform cannot receive keyboard input for the confirmation prompt; passing -auto-approve to apply causes it to accept the generated plan and execute the changes without waiting for a typed yes.

Why A is correct: Correct: -auto-approve tells apply to bypass the yes prompt, which is exactly what an unattended pipeline needs.

Why B is wrong: Tempting because -auto-approve is the right flag, but plan never changes infrastructure and does not accept that flag, so nothing would be applied.

Why C is wrong: The -input=false flag only disables prompting for missing variables; with no approval given the apply errors out rather than proceeding.

Why D is wrong: Disabling the state lock affects concurrency safety, not the approval prompt, so apply would still halt waiting for a yes.

Free sampleCore Terraform workfloweasy

A team lead wants a continuous integration job to fail whenever a submitted configuration is not in canonical format, without the job modifying any files in the checkout. Which terraform fmt invocation meets this requirement?

# CI pipeline step
terraform fmt <flag>
  • Aterraform fmt -recursive
  • Bterraform fmt -check Correct
  • Cterraform fmt -write=true
  • Dterraform fmt -json
Identify that terraform fmt -check reports formatting problems and fails without rewriting files, suiting continuous integration gates. With -check, terraform fmt performs a read-only comparison against canonical style and signals its verdict through the exit code, so an automated pipeline can reject non-canonical configurations while leaving the working tree untouched.

Why A is wrong: -recursive extends formatting into subdirectories but still rewrites files in place, so the job would edit the checkout rather than simply failing on badly formatted input.

Why B is correct: The -check flag reports whether files are already in canonical format and returns a non-zero exit code if any are not, all without writing changes, which is exactly what a gating CI job needs.

Why C is wrong: This is the default behaviour that overwrites files with the canonical form; a CI gate must not modify the checkout, and it would not fail on unformatted input.

Why D is wrong: -json changes the output format to machine-readable JSON but, without -check, still rewrites files and does not by itself turn unformatted input into a failing exit code.

Other domains in this exam

See also the TF-Associate-004 cert hub, the study guide, and the cheat sheet.

Examworthy is not affiliated with or endorsed by HashiCorp. Original, blueprint-aligned practice material only.