TA-002-P · Question #74
How is terraform import run?
The correct answer is B. As a part of terraform plan. While terraform import is a standalone command, newer Terraform versions (1.5+) allow import operations to be defined in import blocks within HCL, which are then processed and previewed as part of the terraform plan lifecycle.
Question
How is terraform import run?
Options
- AAs a part of terraform init
- BAs a part of terraform plan
- CAs a part of terraform refresh
- DBy an explicit call
- EAll of the above
How the community answered
(28 responses)- B93% (26)
- C4% (1)
- D4% (1)
Why each option
While `terraform import` is a standalone command, newer Terraform versions (1.5+) allow import operations to be defined in `import` blocks within HCL, which are then processed and previewed as part of the `terraform plan` lifecycle.
`terraform init` initializes the working directory, downloads providers, and sets up backends; it does not involve importing resources.
With the introduction of `import` blocks in Terraform 1.5, the definition of resources to be imported can be integrated directly into the Terraform configuration. When such an `import` block is present, `terraform plan` will evaluate the configuration and determine the resources that *will be imported* during the subsequent `terraform apply`, thus making the import process conceptually visible or 'part of' the planning stage, even if the actual import occurs during `apply`.
`terraform refresh` updates the state file to reflect the current real-world infrastructure, but it does not import new, unmanaged resources into the state.
While `terraform import` (the CLI command) is run by an explicit call, the question might be implicitly referring to how import operations are integrated into the overall Terraform workflow with `import` blocks, where `plan` plays a crucial role.
`terraform import` (the command) is not part of `init`, `plan`, or `refresh` commands directly, and `import` blocks are specifically part of the `plan/apply` lifecycle, not all of them.
Concept tested: Terraform import process lifecycle
Source: https://developer.hashicorp.com/terraform/language/import
Topics
Community Discussion
No community discussion yet for this question.