What is the purpose of the Terraform import command?
The Terraform import command is used to bring existing infrastructure resources into Terraform's management without recreating them.
Click to reveal answer
beginner
How does Terraform import affect the state file?
Terraform import adds the existing resource to the Terraform state file, allowing Terraform to track and manage it going forward.
Click to reveal answer
intermediate
Can Terraform import create resource configuration automatically?
No, Terraform import only updates the state file. You must manually write the resource configuration in your Terraform files to match the imported resource.
Click to reveal answer
beginner
What is the general syntax of the Terraform import command?
3. Given this Terraform import command: terraform import aws_instance.web i-1234567890abcdef0 What will Terraform do after running this command?
medium
A. Create a new AWS instance with ID i-1234567890abcdef0
B. Delete the AWS instance i-1234567890abcdef0
C. Add the existing AWS instance i-1234567890abcdef0 to Terraform state under aws_instance.web
D. Update the AWS instance i-1234567890abcdef0 with Terraform configuration
Solution
Step 1: Understand import effect on state
The import command adds an existing resource to Terraform's state file without creating or deleting it.
Step 2: Clarify what happens to the resource
The resource remains unchanged in the cloud; Terraform just tracks it as aws_instance.web.
Final Answer:
Add the existing AWS instance i-1234567890abcdef0 to Terraform state under aws_instance.web -> Option C
Quick Check:
Import adds resource to state, no creation or deletion [OK]
Hint: Import updates state, not cloud resources [OK]
Common Mistakes:
Thinking import creates or deletes resources
Assuming import applies configuration changes
Confusing import with terraform apply
4. You ran terraform import aws_s3_bucket.example my-bucket but got an error: Resource aws_s3_bucket.example not found in configuration. What is the likely cause?
medium
A. The import command syntax is incorrect
B. The bucket my-bucket does not exist in AWS
C. Terraform version is outdated
D. The resource aws_s3_bucket.example is missing in Terraform files
Solution
Step 1: Analyze error message
The error says the resource address is not found in configuration, meaning Terraform files lack aws_s3_bucket.example.
Step 2: Confirm resource presence
Before import, Terraform must know the resource block to map the imported resource correctly.
Final Answer:
The resource aws_s3_bucket.example is missing in Terraform files -> Option D
Quick Check:
Resource must exist in config before import [OK]
Hint: Define resource in config before importing [OK]
Common Mistakes:
Ignoring missing resource block
Assuming import creates resource block
Blaming AWS resource existence first
5. You imported an existing AWS security group with terraform import aws_security_group.sg sg-0a1b2c3d4e5f6g7h8. After import, your Terraform configuration does not match the actual security group rules. What should you do next?
hard
A. Manually update your Terraform configuration to match the imported resource
B. Run terraform apply immediately to fix the resource
C. Delete the imported resource from state and re-import
D. Nothing, Terraform will auto-sync configuration
Solution
Step 1: Understand import limitations
Import adds the resource to state but does not update Terraform files to reflect actual settings.
Step 2: Align configuration with reality
You must manually edit Terraform configuration to match the imported resource's current rules to avoid unwanted changes on apply.
Final Answer:
Manually update your Terraform configuration to match the imported resource -> Option A
Quick Check:
Update config after import to match resource [OK]
Hint: Edit config to match imported resource before apply [OK]
Common Mistakes:
Expecting terraform apply to fix config automatically
Deleting and re-importing unnecessarily
Ignoring config mismatch risks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.