TF-004 Use Terraform outside the core workflow Practice Question
Which Terraform command is used to bring existing infrastructure that was created outside of Terraform under Terraform management?
⚠ Common exam trap
The exam often tests the distinction between `terraform import` (which adds external resources to state) and `terraform refresh` (which only syncs state for already-managed resources), leading candidates to mistakenly choose `terraform refresh` when they need to bring new resources under management.
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
✓
terraform import
`terraform import` is the dedicated command to bring existing infrastructure that was created outside of Terraform under Terraform management. It maps the real-world resource ID to a Terraform resource address in state, allowing Terraform to track and manage that resource without recreating it.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
terraform state push
Why it's wrong here
The "terraform state push" command is specifically designed for manually uploading a local Terraform state file to a configured remote backend. This operation is crucial for maintaining state consistency across distributed teams or for disaster recovery scenarios involving state file corruption, ensuring the remote backend accurately reflects the desired state. However, its scope is strictly limited to state file synchronization and does not involve interacting with existing cloud resources to bring them under Terraform management.
- ✗
terraform apply
Why it's wrong here
The "terraform apply" command is used to execute the actions proposed in a Terraform plan, which primarily involves provisioning new infrastructure, modifying existing resources to match the configuration, or destroying resources no longer defined. While it manages the lifecycle of resources already defined in your configuration, it lacks the functionality to discover and incorporate infrastructure that was provisioned outside of Terraform into the state file. Its fundamental role is to reconcile the desired state, as expressed in HCL, with the current state of the infrastructure.
- ✓
terraform import
Why this is correct
The "terraform import" command is the designated tool for incorporating existing infrastructure resources into Terraform's state management. This process requires specifying the Terraform resource address and the unique identifier of the existing cloud resource, effectively linking them within the state file. Once imported, Terraform can then manage the lifecycle of that previously unmanaged resource, allowing subsequent "terraform plan" and "apply" operations to detect and propose changes to it based on the corresponding HCL configuration.
- ✗
terraform refresh
Why it's wrong here
The "terraform refresh" command is utilized to reconcile the Terraform state file with the actual current attributes of the real-world infrastructure that Terraform already manages. It verifies that the state accurately reflects the remote resources, detecting any manual changes made outside of Terraform and updating the state accordingly. However, "terraform refresh" does not discover or add new, unmanaged resources to the state; its function is solely to update the attributes of resources already present and tracked within the state file.
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 →
Same concept, more angles
1 more way this is tested on TF-004
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A team wants to import an existing AWS S3 bucket named 'my-bucket' into Terraform state. The resource block is defined as 'aws_s3_bucket.my_bucket'. Which command should be used?
easy- A.terraform import my-bucket aws_s3_bucket.my_bucket
- B.terraform import 'aws_s3_bucket.my_bucket' 'my-bucket'
- ✓ C.terraform import aws_s3_bucket.my_bucket my-bucket
- D.terraform import aws_s3_bucket.my-bucket my-bucket
Why C: The correct syntax for `terraform import` is `terraform import <resource_address> <id>`, where the resource address is the Terraform resource block identifier (e.g., `aws_s3_bucket.my_bucket`) and the ID is the actual AWS resource identifier (e.g., the bucket name `my-bucket`). Option C follows this exact order: `terraform import aws_s3_bucket.my_bucket my-bucket`, making it the correct command to import the existing S3 bucket into Terraform state.
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.