TF-004 Implement and maintain state Practice Question
Which TWO of the following are valid methods to share data between Terraform configurations?
⚠ Common exam trap
HashiCorp often tests the misconception that output variables alone can be used across configurations, but they require an explicit data source like `terraform_remote_state` to be consumed externally.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Store shared data in a common backend and read it via data sources
Storing shared data in a common backend (e.g., an S3 bucket with DynamoDB locking) and reading it via data sources (like the `terraform_remote_state` data source) allows different Terraform configurations to consume outputs from one another without duplicating state or breaking isolation. This pattern is the recommended way to share data across configurations because it leverages the backend's locking and consistency guarantees.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use output variables across configurations
Why it's wrong here
Output variables are designed to display values from a single Terraform configuration after an apply, or for consumption by external tools. They do not inherently provide a mechanism to directly share data between distinct Terraform configurations, each with its own state file, without explicitly leveraging remote state capabilities.
- ✗
Use modules to share state
Why it's wrong here
Terraform modules serve as reusable blueprints for infrastructure code, encapsulating resources, data sources, and variables within a single logical unit. While modules help organize and abstract configuration, they do not facilitate the sharing of *state* itself between separate root configurations; each root configuration maintains its own independent state file.
- ✗
Use depends_on to pass values
Why it's wrong here
`depends_on` is a meta-argument that explicitly defines an ordering dependency between resources, ensuring that one resource is created or updated only after another specified resource has completed. This mechanism solely controls the sequence of operations during planning and application, and it does not enable the passing of actual data values or attributes between resources.
- ✓
Store shared data in a common backend and read it via data sources
Why this is correct
Storing shared data in a common backend, such as an S3 bucket or Consul Key-Value store, allows different Terraform configurations to access specific values. Data sources like `aws_s3_bucket_object` or `consul_kv` can then be used to retrieve these arbitrary pieces of information, providing a flexible method for cross-configuration data exchange beyond just Terraform state outputs.
- ✓
Use terraform_remote_state data source
Why this is correct
The `terraform_remote_state` data source is specifically designed to read output values from a *remote Terraform state file* managed by a different configuration. By specifying the backend configuration of the remote state, one Terraform configuration can securely consume the outputs, such as resource IDs or connection strings, generated by another independent configuration.
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.