Bird
Raised Fist0
Terraformcloud~20 mins

Import limitations and considerations in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Terraform Import Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Terraform Import Limitations

Which of the following is NOT a limitation when using terraform import?

ATerraform import does not create resource configuration in code; it only maps existing resources to state.
BImported resources must have a unique ID that Terraform can recognize.
CTerraform import cannot import resources that are managed outside of Terraform.
DTerraform import can import multiple resources at once using a single command.
Attempts:
2 left
💡 Hint

Think about what terraform import actually does versus what it cannot do.

❓ Architecture
intermediate
2:00remaining
Importing Resources with Complex Dependencies

You have a Terraform configuration with resources that depend on each other. What is the best practice when importing these resources?

AImport resources starting from the ones with no dependencies, then import dependent resources in order.
BImport only the top-level resource; dependent resources will be imported automatically.
CDelete dependent resources before importing the main resource.
DImport all resources in any order; Terraform will automatically resolve dependencies.
Attempts:
2 left
💡 Hint

Think about how Terraform manages dependencies and state.

❓ security
advanced
2:00remaining
Security Considerations When Importing Resources

Which security risk is most relevant when importing existing cloud resources into Terraform?

ATerraform import automatically encrypts all resource data during import.
BTerraform import deletes existing resources to secure them.
CTerraform import exposes resource secrets in the state file if not handled properly.
DTerraform import disables all resource access policies temporarily.
Attempts:
2 left
💡 Hint

Consider what information Terraform state files contain after import.

✅ Best Practice
advanced
2:00remaining
Handling Resource Configuration After Import

After importing a resource into Terraform state, what is the recommended next step to ensure proper management?

ARun <code>terraform apply</code> immediately without any configuration changes.
BManually write the resource configuration in Terraform code to match the imported resource.
CDelete the imported resource from the cloud provider to avoid conflicts.
DIgnore the imported resource and manage it outside Terraform.
Attempts:
2 left
💡 Hint

Think about how Terraform manages resources and configuration files.

❓ service_behavior
expert
2:00remaining
Terraform Import Behavior with Resources Having Dynamic IDs

Consider a cloud resource whose ID changes dynamically after creation (e.g., a load balancer with a generated ID). What happens if you import this resource into Terraform and then the ID changes in the cloud provider?

ATerraform state will become out of sync, causing errors on next plan or apply.
BTerraform automatically updates the state with the new resource ID without user action.
CTerraform deletes the resource and recreates it with the old ID.
DTerraform ignores the ID change and continues managing the resource without issues.
Attempts:
2 left
💡 Hint

Think about how Terraform tracks resources using IDs in state.

Practice

(1/5)
1. What is the main purpose of the terraform import command?
easy
A. To delete resources from the cloud provider
B. To create new resources from scratch
C. To bring existing resources under Terraform management without recreating them
D. To update Terraform itself to the latest version

Solution

  1. Step 1: Understand the role of terraform import

    The terraform import command is used to take resources that already exist outside Terraform and bring them into Terraform's control without deleting or recreating them.
  2. Step 2: Differentiate from other commands

    Creating new resources is done with terraform apply, deleting is done with terraform destroy, and updating Terraform is unrelated to resource import.
  3. Final Answer:

    To bring existing resources under Terraform management without recreating them -> Option C
  4. Quick Check:

    terraform import = bring existing resources under control [OK]
Hint: Import means adopt existing resources, not create new ones [OK]
Common Mistakes:
  • Thinking import creates new resources
  • Confusing import with resource deletion
  • Assuming import updates Terraform version
2. Which of the following is required before running terraform import for a resource?
easy
A. The resource must be deleted first
B. The resource must be created by Terraform previously
C. Terraform must be initialized with terraform init after import
D. The resource configuration must exist in the Terraform files

Solution

  1. Step 1: Check Terraform import requirements

    Before importing, Terraform needs a matching resource block in the configuration files to map the imported resource to.
  2. Step 2: Understand other options

    The resource should not be deleted before import; terraform init is run before import, not after; and the resource does not need to be created by Terraform previously.
  3. Final Answer:

    The resource configuration must exist in the Terraform files -> Option D
  4. Quick Check:

    Config must exist before import [OK]
Hint: Write resource config first, then import [OK]
Common Mistakes:
  • Trying to import without resource config
  • Deleting resource before import
  • Running terraform init after import
3. Given this Terraform resource configuration:
resource "aws_s3_bucket" "mybucket" {
  bucket = "my-existing-bucket"
}

What happens if you run terraform import aws_s3_bucket.mybucket my-existing-bucket?
medium
A. Terraform imports the existing S3 bucket and manages it without changes
B. Terraform deletes the existing bucket and creates a new one
C. Terraform throws an error because the bucket name is missing
D. Terraform creates a duplicate bucket with a different name

Solution

  1. Step 1: Match resource config and import command

    The resource block matches the bucket name used in the import command, so Terraform will link the existing bucket to this resource.
  2. Step 2: Understand import behavior

    Import does not delete or recreate resources; it only brings them under Terraform management.
  3. Final Answer:

    Terraform imports the existing S3 bucket and manages it without changes -> Option A
  4. Quick Check:

    Import links existing resource without changes [OK]
Hint: Import links existing resource, no deletion [OK]
Common Mistakes:
  • Assuming import deletes or recreates resource
  • Confusing import with apply
  • Using wrong resource ID format
4. You run terraform import aws_instance.web i-1234567890abcdef0 but get an error saying the resource ID format is invalid. What is the most likely cause?
medium
A. Terraform was not initialized with terraform init
B. The resource ID does not match the expected format for the AWS provider
C. The resource configuration block is missing in Terraform files
D. The AWS instance does not exist in the cloud

Solution

  1. Step 1: Check resource ID format

    Terraform import requires the resource ID to match the provider's expected format exactly. An invalid format causes errors.
  2. Step 2: Differentiate from other causes

    Missing config causes different errors; uninitialized Terraform causes different errors; non-existent resource causes not found errors, not format errors.
  3. Final Answer:

    The resource ID does not match the expected format for the AWS provider -> Option B
  4. Quick Check:

    Invalid ID format causes import error [OK]
Hint: Check provider docs for correct ID format before import [OK]
Common Mistakes:
  • Ignoring ID format requirements
  • Assuming missing config causes format error
  • Skipping terraform init before import
5. You want to import multiple existing resources of the same type but with different IDs into Terraform. Which approach best handles this scenario?
hard
A. Write separate resource blocks with unique names and import each resource individually
B. Write one resource block and import all IDs at once using a comma-separated list
C. Use a single resource block with a list of IDs and import once
D. Import resources without any configuration blocks and Terraform will auto-discover them

Solution

  1. Step 1: Understand Terraform resource uniqueness

    Each resource block must have a unique name to represent a single resource instance in Terraform.
  2. Step 2: Import multiple resources properly

    To import multiple resources, create multiple resource blocks with unique names and import each resource ID separately.
  3. Step 3: Eliminate incorrect options

    Terraform does not support importing multiple IDs at once in one resource block or auto-discovery without config.
  4. Final Answer:

    Write separate resource blocks with unique names and import each resource individually -> Option A
  5. Quick Check:

    One resource block per resource, import individually [OK]
Hint: One resource block per resource, import separately [OK]
Common Mistakes:
  • Trying to import multiple IDs in one resource block
  • Assuming Terraform auto-discovers resources
  • Using comma-separated IDs in import command
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