Question 1 · choose 1
A storage bucket was created by hand and must now be managed by Terraform. The team writes a matching resource block and wants to preview the import in a plan before anything is recorded. What should it add?
- AA data block for the bucket, which Terraform converts to a managed resource on apply
- BA moved block from the bucket's cloud ID to the resource address
- CA lifecycle block with ignore_changes = all, so Terraform adopts the bucket as it is
- DAn import block with to and id, then plan and apply
Show the answer and why
AA data block for the bucket, which Terraform converts to a managed resource on apply
Incorrect
Data sources only read objects; they never become managed resources.
BA moved block from the bucket's cloud ID to the resource address
Incorrect
moved changes addresses of objects already in state; it cannot bring in new objects.
CA lifecycle block with ignore_changes = all, so Terraform adopts the bucket as it is
Incorrect
ignore_changes affects updates of managed objects; it does not import anything.
DAn import block with to and id, then plan and apply
Correct
Import blocks are part of the configuration, so the import appears in the plan for review and is recorded in state on apply.
Import blocks make imports part of the normal plan and apply workflow.
HashiCorp documentation
- Data sources (read-only lookups, when they are read) (opens in a new tab)
- moved block reference (from, to) (opens in a new tab)
- lifecycle meta-argument (ignore_changes) (opens in a new tab)
- Import existing resources with import blocks (plan, apply, generated configuration) (opens in a new tab)
- import block reference (to and id) (opens in a new tab)