0
0
Terraformcloud~20 mins

Import block syntax (Terraform 1.5+) - Practice Problems & Coding Challenges

Choose your learning style9 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 the purpose of the import block in Terraform 1.5+

What is the main purpose of the import block introduced in Terraform 1.5+?

ATo automatically create new resources in the cloud provider without any configuration.
BTo declare resources that Terraform should import into the state during <code>terraform apply</code> without manual CLI commands.
CTo remove resources from the Terraform state without deleting them from the cloud provider.
DTo define variables that are imported from external files during plan execution.
Attempts:
2 left
💡 Hint

Think about how Terraform manages existing resources that were created outside Terraform.

Configuration
intermediate
2:00remaining
Identifying correct import block syntax

Which of the following Terraform snippets correctly uses the import block syntax introduced in Terraform 1.5+ to import an AWS S3 bucket with ID my-bucket?

A
import {
  to = aws_s3_bucket.example
  id = "my-bucket"
}
B
import {
  id = aws_s3_bucket.example
  to = "my-bucket"
}
C
import {
  resource = aws_s3_bucket.example
  id = "my-bucket"
}
D
import {
  id = "my-bucket"
  to = aws_s3_bucket.example
}
Attempts:
2 left
💡 Hint

The import block requires id and to attributes. The order matters for clarity.

Architecture
advanced
2:00remaining
Behavior of import block during terraform apply

What happens when Terraform runs terraform apply with a configuration that includes an import block for a resource that already exists in the cloud provider but is not yet in the Terraform state?

ATerraform imports the resource into the state automatically before applying any changes.
BTerraform ignores the import block and creates a new resource instead.
CTerraform throws an error and stops the apply process.
DTerraform deletes the existing resource and creates a new one.
Attempts:
2 left
💡 Hint

Consider how Terraform handles existing resources declared in the import block during apply.

security
advanced
2:00remaining
Security considerations when using import blocks

Which security risk is most relevant when using Terraform's import block to bring existing cloud resources into state?

AAccidentally importing sensitive resources without proper access controls in Terraform state files.
BTerraform automatically encrypts all imported resource data, so no risks exist.
CImport blocks expose cloud provider credentials in the Terraform configuration files.
DImport blocks delete existing resources during import, causing data loss.
Attempts:
2 left
💡 Hint

Think about what information is stored in Terraform state files after import.

service_behavior
expert
2:00remaining
Effect of multiple import blocks for the same resource

Given a Terraform configuration with two import blocks referencing the same resource address but different IDs, what will happen during terraform apply?

ATerraform will ignore the second import block and only import the first resource ID.
BTerraform will import the resource twice, causing duplicate state entries.
CTerraform will raise an error about conflicting import declarations and stop the apply.
DTerraform will merge both IDs and create a new resource combining them.
Attempts:
2 left
💡 Hint

Consider how Terraform handles conflicting state imports for the same resource address.