What is the purpose of writing configuration for imported resources in Terraform?
It allows Terraform to manage existing infrastructure by matching the imported resource with its configuration, so future changes can be tracked and applied.
Click to reveal answer
beginner
After importing a resource, why must you write its configuration in Terraform files?
Because importing only adds the resource to the state file; without configuration, Terraform doesn't know how to manage or update the resource.
Click to reveal answer
beginner
True or False: Terraform import automatically creates the resource configuration file.
False. Terraform import only updates the state. You must manually write the resource configuration to match the imported resource.
Click to reveal answer
intermediate
What is a best practice when writing configuration for imported resources?
Use the exact resource attributes as they exist in the cloud provider to avoid unexpected changes during future Terraform runs.
Click to reveal answer
beginner
How can you verify that your imported resource configuration matches the actual resource?
Run 'terraform plan' to see if Terraform wants to make any changes. If no changes are planned, the configuration matches the resource.
Click to reveal answer
What does 'terraform import' do?
AAdds an existing resource to Terraform state without creating configuration
After running terraform import aws_vpc.main vpc-1234abcd, Terraform plan shows it wants to change the CIDR block. What is the likely cause?
medium
A. The actual VPC CIDR block differs from the configured one
B. Terraform import failed and did not link the resource
C. The resource name in config does not match the import command
D. Terraform requires a different syntax for VPC import
Solution
Step 1: Analyze import and plan behavior
Import links the existing VPC to Terraform state, but if the configuration CIDR block differs from the actual VPC, Terraform plans to update it.
Step 2: Identify cause of plan changes
The difference in CIDR block values causes Terraform to want to change the resource to match config, which is not allowed for VPC CIDR.
Final Answer:
The actual VPC CIDR block differs from the configured one -> Option A
Quick Check:
Config mismatch causes plan changes [OK]
Hint: Check config matches actual resource attributes exactly [OK]
Common Mistakes:
Assuming import failed without checking state
Confusing resource name with import ID
Thinking import syntax is wrong
5. You have an existing Azure resource group named rg-prod created outside Terraform. You want to import it and manage it with Terraform. Which steps correctly describe the process?
hard
A. Create a new resource group in Terraform, then delete the existing one manually.
B. Run 'terraform import' first without any resource block, then write the resource block after.
C. Write a resource block with any name, run 'terraform import' with resource group name only, then apply.
D. Write a resource block with name 'rg-prod', run 'terraform import azurerm_resource_group.prod /subscriptions/0000/resourceGroups/rg-prod', then run 'terraform plan' to verify.
Solution
Step 1: Write matching resource block
Before importing, write a resource block with the correct resource type and name matching the existing resource group.
Step 2: Run terraform import with full resource ID
Use the full Azure resource ID to import the existing resource group into Terraform state.
Step 3: Verify with terraform plan
Run 'terraform plan' to confirm Terraform recognizes the imported resource and no unexpected changes are planned.
Final Answer:
Write a resource block with name 'rg-prod', run 'terraform import azurerm_resource_group.prod /subscriptions/0000/resourceGroups/rg-prod', then run 'terraform plan' to verify. -> Option D
Quick Check:
Config first, import with full ID, then plan [OK]
Hint: Write config first, import with full ID, then plan [OK]
Common Mistakes:
Importing without resource block
Using partial resource ID in import
Creating duplicate resources instead of importing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.