What is the main purpose of bulk import strategies in Terraform?
Bulk import strategies help bring many existing cloud resources under Terraform management efficiently, saving time and reducing manual work.
Click to reveal answer
intermediate
How does the 'terraform import' command work in bulk import scenarios?
The 'terraform import' command links an existing resource to a Terraform resource block, but it works one resource at a time, so scripts or loops are used to import many resources.
Click to reveal answer
beginner
Why is scripting important in bulk import strategies?
Scripting automates repetitive import commands, making it faster and less error-prone to import many resources at once.
Click to reveal answer
intermediate
What is a common challenge when performing bulk imports in Terraform?
Ensuring the Terraform configuration matches the existing resources exactly to avoid drift or errors after import.
Click to reveal answer
beginner
Name one best practice for bulk importing resources into Terraform.
Test imports on a small set of resources first, verify the state, then scale up to bulk import to avoid mistakes.
Terraform resource names must use underscores (_) not dashes (-).
Step 2: Identify cause of error
The error says resource name must not contain '-', so using dashes in resource names causes this error.
Final Answer:
Using resource names with dashes (-) which Terraform disallows -> Option A
Quick Check:
Resource names cannot have '-' [OK]
Hint: Use underscores (_) in resource names, not dashes (-) [OK]
Common Mistakes:
Ignoring naming rules and using dashes
Assuming missing init causes this error
Blaming credentials for naming errors
5. You want to bulk import 100 existing Azure VMs into Terraform. Which approach best follows Terraform bulk import best practices?
hard
A. Run terraform import once with all VM IDs separated by commas
B. Write a script that loops over VM IDs, runs terraform import for each, and maintains matching Terraform config files
C. Manually import each VM one by one using terraform import command
D. Create new Terraform resources and delete existing VMs to sync state
Solution
Step 1: Understand bulk import best practice
Bulk import works best with automation scripts looping over resource IDs to import each resource.
Step 2: Match Terraform configuration
Terraform requires matching resource blocks in config files for imported resources to manage them properly.
Step 3: Evaluate options
Write a script that loops over VM IDs, runs terraform import for each, and maintains matching Terraform config files uses scripting and matching config, Run terraform import once with all VM IDs separated by commas is invalid syntax, Manually import each VM one by one using terraform import command is slow manual work, Create new Terraform resources and delete existing VMs to sync state deletes resources which is unsafe.
Final Answer:
Write a script that loops over VM IDs, runs terraform import for each, and maintains matching Terraform config files -> Option B
Quick Check:
Automate import with matching config files [OK]
Hint: Automate imports with scripts and matching config files [OK]
Common Mistakes:
Trying to import multiple IDs in one command
Manually importing many resources without automation
Deleting resources instead of importing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.