Bird
Raised Fist0
Terraformcloud~20 mins

Bulk import strategies in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Bulk Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Architecture
intermediate
2:00remaining
Choosing the best bulk import method for large resource sets

You have thousands of existing cloud resources to manage with Terraform. Which bulk import strategy is most efficient and scalable?

AManually write all resource blocks in Terraform and skip importing existing resources.
BManually run terraform import for each resource one by one using a shell script loop.
CUse terraform import with a generated script that runs imports in parallel batches.
DDelete all existing resources and recreate them with Terraform from scratch.
Attempts:
2 left
💡 Hint

Think about automation and speed when importing many resources.

❓ Configuration
intermediate
2:00remaining
Terraform import command for multiple resources

You want to import multiple AWS S3 buckets into Terraform state using a script. Which command snippet correctly imports all buckets listed in a file named buckets.txt?

Aterraform import aws_s3_bucket.* buckets.txt
Bfor bucket in $(cat buckets.txt); do terraform import aws_s3_bucket.$bucket $bucket; done
Cterraform import aws_s3_bucket.buckets.txt buckets.txt
Dterraform import aws_s3_bucket $bucket < buckets.txt
Attempts:
2 left
💡 Hint

Consider how to loop over each bucket name and run import separately.

❓ service_behavior
advanced
2:00remaining
Effect of importing resources without matching configuration

What happens if you run terraform import on a resource that is not defined in your Terraform configuration files?

ATerraform imports the resource into state but will ignore it during plan and apply until configuration exists.
BTerraform imports the resource into state but will show it as 'tainted' until configuration is added.
CTerraform throws an error and refuses to import the resource without matching configuration.
DTerraform imports the resource and automatically creates a default configuration block.
Attempts:
2 left
💡 Hint

Think about how Terraform manages state versus configuration.

❓ security
advanced
2:00remaining
Security risks during bulk import of cloud resources

Which security risk is most relevant when performing bulk import of existing cloud resources into Terraform state?

ATerraform may overwrite resource permissions during import causing privilege escalation.
BBulk import deletes existing resources to recreate them with default security settings.
CTerraform import automatically disables resource encryption during import.
DImporting resources requires exposing sensitive credentials in scripts or logs.
Attempts:
2 left
💡 Hint

Consider what credentials and data are needed to run import commands safely.

✅ Best Practice
expert
2:00remaining
Best practice for managing state consistency during bulk import

When importing thousands of resources in bulk, what is the best practice to ensure Terraform state consistency and avoid conflicts?

ALock the remote state backend and run imports sequentially or in controlled batches.
BRun all imports concurrently on multiple machines writing to the same remote state backend.
CDisable state locking and run imports in parallel to speed up the process.
DExport the state to local files and merge manually after imports complete.
Attempts:
2 left
💡 Hint

Think about how Terraform prevents state corruption during concurrent operations.

Practice

(1/5)
1. What is the main purpose of using bulk import strategies in Terraform?
easy
A. To automatically generate Terraform code for new resources
B. To create new resources faster than usual
C. To delete multiple resources simultaneously
D. To efficiently bring many existing resources under Terraform management at once

Solution

  1. Step 1: Understand Terraform import

    Terraform import lets you bring existing cloud resources into Terraform state so you can manage them.
  2. Step 2: Recognize bulk import purpose

    Bulk import strategies help import many resources quickly instead of one by one.
  3. Final Answer:

    To efficiently bring many existing resources under Terraform management at once -> Option D
  4. Quick Check:

    Bulk import = manage many existing resources [OK]
Hint: Bulk import means importing many existing resources at once [OK]
Common Mistakes:
  • Thinking bulk import creates new resources
  • Confusing import with resource deletion
  • Assuming import auto-generates Terraform code
2. Which Terraform command is used to import a resource into the state file?
easy
A. terraform import
B. terraform plan
C. terraform init
D. terraform apply

Solution

  1. Step 1: Recall Terraform commands

    terraform apply creates or updates resources, terraform init initializes, terraform plan previews changes.
  2. Step 2: Identify import command

    terraform import is the command that brings existing resources into Terraform state.
  3. Final Answer:

    terraform import -> Option A
  4. Quick Check:

    Import command = terraform import [OK]
Hint: Import existing resources with 'terraform import' command [OK]
Common Mistakes:
  • Using terraform apply to import
  • Confusing init with import
  • Trying terraform plan to import
3. Given this script snippet to bulk import AWS EC2 instances:
for id in i-12345678 i-87654321; do terraform import aws_instance.example_$id $id; done
What will be the result after running this script?
medium
A. Terraform will create new instances instead of importing
B. Only the first instance will be imported, second will fail
C. Both instances will be imported with resource names aws_instance.example_i-12345678 and aws_instance.example_i-87654321
D. The script will cause a syntax error and not run

Solution

  1. Step 1: Analyze the for loop

    The loop iterates over two instance IDs: i-12345678 and i-87654321.
  2. Step 2: Understand terraform import usage

    Each iteration runs terraform import with resource name aws_instance.example_$id and the ID as argument, importing both instances.
  3. Final Answer:

    Both instances will be imported with resource names aws_instance.example_i-12345678 and aws_instance.example_i-87654321 -> Option C
  4. Quick Check:

    Loop imports both instances correctly [OK]
Hint: Loop imports each resource with unique name using ID [OK]
Common Mistakes:
  • Assuming only one import runs
  • Thinking terraform creates new instances
  • Believing script syntax is invalid
4. You wrote a bulk import script but get errors: "Error: Resource name must not contain '-'". What is the likely cause?
medium
A. Using resource names with dashes (-) which Terraform disallows
B. Missing terraform init before import
C. Incorrect AWS credentials causing import failure
D. Trying to import resources that do not exist

Solution

  1. Step 1: Understand Terraform resource naming rules

    Terraform resource names must use underscores (_) not dashes (-).
  2. Step 2: Identify cause of error

    The error says resource name must not contain '-', so using dashes in resource names causes this error.
  3. Final Answer:

    Using resource names with dashes (-) which Terraform disallows -> Option A
  4. 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

  1. Step 1: Understand bulk import best practice

    Bulk import works best with automation scripts looping over resource IDs to import each resource.
  2. Step 2: Match Terraform configuration

    Terraform requires matching resource blocks in config files for imported resources to manage them properly.
  3. 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.
  4. Final Answer:

    Write a script that loops over VM IDs, runs terraform import for each, and maintains matching Terraform config files -> Option B
  5. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard