0
0
Terraformcloud~5 mins

Import block syntax (Terraform 1.5+) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the import block in Terraform 1.5+?
The import block lets you bring existing infrastructure resources into Terraform's management by specifying their IDs directly in the configuration.
Click to reveal answer
beginner
How do you specify the resource to import using the new import block syntax?
You specify the resource address and the ID of the existing resource inside the <code>import</code> block, like this:<br><pre>import {
  to = aws_instance.example
  id = "i-1234567890abcdef0"
}</pre>
Click to reveal answer
intermediate
Can you use multiple import blocks in a single Terraform configuration?
Yes, you can use multiple <code>import</code> blocks to import several resources at once, each with its own <code>to</code> and <code>id</code> values.
Click to reveal answer
intermediate
What happens if you try to import a resource that is already managed by Terraform?
Terraform will show an error because the resource is already tracked in the state. You should only import resources not yet managed.
Click to reveal answer
advanced
Why is the import block syntax preferred over the old CLI import command?
The import block syntax allows you to declare imports as part of your configuration files, making imports repeatable, version-controlled, and easier to automate.
Click to reveal answer
What key fields must an import block contain in Terraform 1.5+?
A<code>address</code> and <code>type</code>
B<code>resource</code> and <code>name</code>
C<code>source</code> and <code>destination</code>
D<code>to</code> and <code>id</code>
Can the import block be used to create new resources in Terraform?
ANo, it only imports existing resources
BYes, it creates new resources automatically
CYes, but only for AWS resources
DNo, it deletes existing resources
Which Terraform version introduced the import block syntax?
ATerraform 0.12
BTerraform 1.0
CTerraform 1.5
DTerraform 2.0
What is the benefit of declaring imports in Terraform configuration files?
AImports become part of version control and automation
BImports run faster
CImports require no resource IDs
DImports automatically update resource code
If you want to import multiple resources, what should you do?
AUse one import block with multiple IDs
BUse multiple import blocks, one per resource
CImport only one resource at a time
DUse the CLI import command instead
Explain how the import block syntax works in Terraform 1.5+ and why it is useful.
Think about how Terraform manages resources and why importing is needed.
You got /4 concepts.
    Describe the steps to import an existing AWS instance using the import block syntax.
    Focus on the syntax and the process flow.
    You got /4 concepts.