cert-bank

Guides

이 글을 한국어로 읽기

Terraform Associate (004) Study Guide: Configuration, State and Real Infrastructure, and Which Command Touches Which

Most Terraform Associate questions come down to one question in disguise: which of three things does this command or block change? There is the configuration you write, the state Terraform keeps, and the real infrastructure in the cloud. Once you can say, for every command, which of the three it reads and which it writes, a large part of the exam becomes predictable. This guide is built around that idea, then covers what changed in the 004 version and how to spread your study time.

Study guide · HashiCorp Certified: Terraform Associate (004) (TF-TA004)

Terraform Associate (004) Study Guide: Configuration, State and Real Infrastructure, and Which Command Touches Which

The exam in brief

The exam lasts one hour, is proctored online and is given in English. It tests Terraform 1.12 and includes HCP Terraform. Question types are true or false, multiple choice and multiple answer; a multiple-answer item tells you how many options to pick. HashiCorp does not publish the number of questions, the pass mark or the weight of each of the eight objectives, so check the official exam page for current details and spread your preparation evenly.

Among the 266 TF-TA004 questions in this question bank, 47 (18%) ask for more than one answer, and the largest group (40%) are use-case questions: "a team wants X, which command or block does it?" About one in five describes something going wrong. The configuration objective has the most questions in our bank because it is the broadest, with eight sub-objectives (4a-4h): variables, expressions, lifecycle rules and custom conditions all live there.

Three things, kept apart

  • Configuration is what you want: the .tf files.
  • State is Terraform's last recorded view: which block is bound to which real object, plus attributes and dependencies.
  • Real infrastructure is what exists right now, whoever created or changed it.

A normal plan reads all three: it refreshes its view of the real objects in state, compares the configuration with that view, and proposes actions. A block with no state entry is planned for creation. A state entry with no block is planned for destruction. An object someone built by hand and never imported is invisible to Terraform.

What a normal plan and apply read and write
1
Refresh
Read the real objects tracked in state and update Terraform's view of them
2
Compare
Compare the configuration with that view; objects never imported stay invisible
3
Plan
A block with no state entry: create. A state entry with no block: destroy. Nothing changes yet.
4
Apply
Change real infrastructure to match the configuration, then record the result in state
Follow the cards to see which of the three, configuration, state or real infrastructure, each step reads or changes.

Which command touches which

Command or blockWhat it changes
init, validate, fmtNeither state nor real infrastructure. Init installs providers and modules and sets up the backend; validate checks syntax, types and references without contacting any API; fmt rewrites file layout only.
planNothing. It is a preview.
apply (normal)Real infrastructure to match the configuration, then state.
apply -refresh-onlyState only, to match reality. No object is created, changed or destroyed.
apply -replace=ADDROne real object is rebuilt although the configuration did not change.
import blockState, after you review it in a plan and apply. The real object is untouched.
terraform import commandState, immediately, with no plan to review.
moved block / state mvThe address an object is tracked under. The block is reviewed and travels with shared code; the command edits one state once.
removed block with destroy = false / state rmState forgets the object; the object keeps running. Without destroy = false a removed block destroys it.
destroyEvery real object the state tracks; their entries leave state.
force-unlockOnly the lock. Neither resources nor state contents.

Many wrong options fail this table. "Use terraform validate to check whether the AMI exists" fails because validate never calls the provider. "Run state rm and leave the block in place" fails because the next plan creates a second copy of the object.

Going deeper: why Terraform cannot work from configuration alone

State holds three things the code cannot supply. First, the binding between an address such as aws_instance.web and a real object ID; without it, a plan against empty state proposes to create everything again, even if the objects exist. Second, dependency information: if you delete a subnet block and the instance block that used it in the same change, nothing in the code says which must go first, but state still records that the instance depends on the subnet, so destroy order is correct. Third, a cache of attributes, which lets very large configurations plan without querying every object (-refresh=false uses it, at the price of missing outside changes). That is why losing state is so expensive: every object has to be imported again.

When the three disagree: drift

Suppose someone resizes an instance in the console. The next normal plan refreshes, sees the difference and proposes to change the instance back. You now have to decide which side is right.

  • The console change was a mistake: apply normally, and the configuration wins.
  • The console change should stay: update the configuration to match. If you only want state to record it first, use apply -refresh-only. On its own, that does not stop the next normal plan from reverting the change.
  • The object was deleted in the console: the plan proposes to create it again.

The old terraform refresh command did the refresh-only update with no review, which is why it is deprecated.

Beginner tip: you do not need a cloud account to see drift. Write one local_file resource (from the hashicorp/local provider) that creates a text file, apply it, then edit the file by hand and run terraform plan. Then try plan -refresh-only, apply -replace, a moved block after renaming the resource, and state rm followed by a plan. Ten minutes of this fills in most of the table above from memory.

What is new in 004

Four topics deserve extra attention because older study material skips them:

  1. depends_on and create_before_destroy are named in the configuration objective. The first adds an ordering Terraform cannot see through references; the second builds the replacement before deleting the old object.
  2. Custom conditions: preconditions check inputs before a resource is handled, postconditions check results after, and check blocks report problems as warnings without stopping the run.
  3. Ephemeral values and write-only arguments, which keep secrets out of state and plan files.
  4. HCP Terraform workspaces and projects, and how an HCP workspace differs from a CLI workspace (our comparison of Terraform state and workspaces covers this in detail).

Learn the current replacements for older habits: apply -refresh-only instead of terraform refresh, apply -replace instead of taint, use_lockfile = true instead of a DynamoDB table for S3 backend locking, and the import block over the import command. The documentation marks refresh, taint and DynamoDB locking as deprecated, so when two options both work, prefer the one it currently recommends.

Going deeper: sensitive hides, ephemeral omits

Marking a variable or output sensitive = true changes only how Terraform displays the value: it is redacted in plan and apply output. The value is still written to state and to saved plan files in plain text, so anyone who can read those files can read the secret. Ephemeral variables and ephemeral resources are different in kind: they exist only during the current operation and are never written to state or plan. A write-only argument (such as password_wo on aws_db_instance) is sent to the provider during each operation and then discarded, never stored in state or plan. If a question asks how to keep a password out of state, "mark it sensitive" is the classic wrong answer.

HCP Terraform in one pass

Objective 8 is about the hosted service. Know these facts:

  • A workspace holds its own state versions, variables, credentials, run history and permissions. Projects group workspaces so access can be granted in bulk.
  • There are three workflows: CLI-driven (a cloud block plus terraform login), VCS-driven (pull requests get speculative plans that can never be applied) and API-driven.
  • Execution mode can be remote, agent or local. In local mode, workspace variables and policy checks are not used.
  • Static provider credentials usually go in as environment variables (dynamic credentials avoid storing them); Terraform variables feed var. inputs. Variable sets share values across workspaces.
  • Run triggers queue a downstream run after an upstream apply. Policy sets (Sentinel or OPA) check plans. Health assessments report drift and failing custom conditions; they never change infrastructure.

A study order

  1. IaC concepts and the core workflow: init, validate, plan, apply, destroy, fmt, and their main flags.
  2. Providers, the lock file and version constraints; then state, backends and locking.
  3. Configuration: variables and precedence, count versus for_each, expressions, lifecycle, custom conditions, secrets.
  4. Modules, then import and the state commands, then HCP Terraform.
  5. Mixed practice sets against a one-hour clock.

Practise

Practise in the question bank: every question explains each option, right and wrong. Start with the domain you just studied, then take a timed mock exam.

Exam facts and objectives as described in HashiCorp's Terraform Associate (004) exam content. Question count, pass mark and objective weights are not published; check the official exam page before you book.