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.
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 approach | Recommended replacement | Why |
|---|---|---|
| terraform refresh | terraform plan or apply -refresh-only | Shows drift before accepting it |
| terraform taint ADDRESS | terraform apply -replace=ADDRESS | Replacement is part of a reviewed plan |
| terraform import ADDRESS ID | import block | Planned, repeatable and can generate configuration |
| terraform state mv | moved block | Reviewed in a plan and recorded in code |
| terraform state rm | removed block with destroy = false | Reviewed in a plan and recorded in code |
| dynamodb_table locking in S3 | use_lockfile = true | DynamoDB locking is deprecated |
Older commands, recommended replacements
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.
Telling the pairs apart
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.
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.