Terraform Associate 004 ยท Maintaining infrastructure
Importing existing infrastructure
import block with to/id, terraform plan -generate-config-out, legacy terraform import command, import brings state only, writing config (7a).
Key points
- An import block has two key arguments: to (the address the object gets in your configuration and state) and id (the real object's identifier at the provider).
- Running terraform plan -generate-config-out=<new file> drafts matching resource blocks.
- Applying an import only records the object in state; it never creates or changes the remote object by itself.
- The older terraform import ADDRESS ID command does one object per run.
Source: https://developer.hashicorp.com/terraform/language/import
Practice questions
Which argument of an import block names the address the imported object will have in Terraform?
- to
- id
- from
- for_each
Show answer
Answer: A. to
to is the destination address in configuration and state. id is the provider-side identifier of the real object, so it answers a different question.
Which statements about import blocks and config generation are true?
- The import is previewed in terraform plan before it is applied
- -generate-config-out may point to an existing file, which Terraform appends to
- The to argument is the resource address the object will have
- Applying an import creates the object if it does not yet exist
- Removing an import block after a successful apply deletes the remote object
Show answer
Answer: A. The import is previewed in terraform plan before it is applied, C. The to argument is the resource address the object will have
Imports show up in the plan and to is the destination address. The output path must be a new file (an existing one causes an error), import only records state, and removing the block does nothing to the remote object.
The legacy terraform import command writes the matching resource block into your .tf files for you.
Show answer
Answer: False
False. The legacy command only records the object in state against an address; you write the configuration yourself. Generating drafts is a feature of plan -generate-config-out.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
