Lesson 3 of 3 Approaching Terraform Associate Questions

Commonly Confused Terraform Concepts

Several pairs of Terraform features sound alike but behave differently, and exam questions often contrast them. This lesson collects the pairs for revision; each is taught in full in its own module.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish pairs of Terraform features that exam questions often contrast.
  • Identify the recommended replacement for each deprecated command.

Hiding values compared with keeping them out of state

Both settings protect secrets, but at different points. sensitive = true controls display only: Terraform redacts the value in plan and apply output, yet still writes it to state and plan files. ephemeral = true on a variable, an ephemeral resource or a write-only argument controls persistence: the value exists only during the run and is never written. The following comparison summarises the difference.

sensitive
Shown in CLI outputNo, redacted
Stored in state and planYes, in plain text
Where it is setVariables and outputs
Choose when You only need to keep a value out of logs and terminal output
ephemeral and write-only
Shown in CLI outputNo
Stored in state and planNo
Where it is setVariables, child module outputs, ephemeral resources and _wo arguments
Choose when A secret must never be persisted

CLI workspaces compared with HCP Terraform workspaces

A CLI workspace, created with terraform workspace new, is an extra state for the same working directory, configuration and backend; it has no variables or permissions of its own. An HCP Terraform workspace is a full unit of management with its own state, variables, run history, settings and team access, normally one per component and environment. When a configuration uses the cloud block with tags, terraform workspace select switches between matching HCP Terraform workspaces.

Commands and their replacements

Several older commands still work but have been replaced by safer, reviewable alternatives. Exams ask for the recommended approach, which is the newer one in every row of the following table.

Older approachRecommended replacementWhy
terraform refreshterraform plan or apply -refresh-onlyShows drift before accepting it
terraform taint ADDRESSterraform apply -replace=ADDRESSReplacement is part of a reviewed plan
terraform import ADDRESS IDimport blockPlanned, repeatable and can generate configuration
terraform state mvmoved blockReviewed in a plan and recorded in code
terraform state rmremoved block with destroy = falseReviewed in a plan and recorded in code
dynamodb_table locking in S3use_lockfile = trueDynamoDB locking is deprecated
Match the pairs

Older commands, recommended replacements

Exam skills 3.5.2 · 6.4.1 · 6.4.3 · 7.1.1

Match each older approach with the recommended replacement.

Log in to try this activity Interactive activities are free with an account.

Other frequent pairs

The following pairs complete the revision list. Each pair is short, but each half answers a different question.

  • resource and data blocks: a resource is managed through its lifecycle; a data source is only read.
  • count and for_each: count addresses instances by index, so removing a middle element shifts later ones; for_each addresses them by key.
  • validate and plan: validate checks the code offline; plan also reads state and real infrastructure.
  • backend and cloud blocks: backend stores state in a storage service; cloud connects to HCP Terraform; a configuration has one or the other.
  • lock file and version constraints: the lock file records provider versions only; modules are kept stable by their version constraints.
  • check blocks and preconditions: a failed check assertion is a warning; a failed precondition or postcondition is an error.
  • references and depends_on: references create implicit dependencies and are preferred; depends_on is for hidden dependencies only.
Match the pairs

Telling the pairs apart

Exam skills 4.1.3 · 4.7.3 · 6.3.1

Match each half of a commonly confused pair with the statement that is true of it.

Log in to try this activity Interactive activities are free with an account.
Worked example

Telling two features apart

A team stores a database administrator password in a variable marked sensitive. An auditor finds the password in the state file in their S3 bucket. The team asks whether a different setting would have prevented this.

The decisive point is persistence, not display.

Sensitive marking worked as designed: the password never appeared in plan output. To keep it out of state, the variable must be declared ephemeral = true and passed to a write-only argument such as password_wo on the database resource, with a password_wo_version that the team increases to rotate it. Encrypting the bucket and restricting access to it remain good practice for everything else that state contains.

Check yourself

What is the recommended replacement for terraform taint?

Show answer

terraform apply -replace=ADDRESS, which shows the replacement in a plan before performing it.

Exam Tips

Remember for the exam

  • sensitive hides; ephemeral and write-only keep values out of state.
  • CLI workspaces are extra states; HCP Terraform workspaces are full management units.
  • The recommended answer is usually the reviewable, plan-based approach.