Resource import adopts an existing infrastructure resource into a provisioning tool’s managed state, allowing infrastructure as code to match live resources without recreating them. After importing, rerun the configuration and inspect the plan to detect and reconcile drift. section 2.2.2 section 13.5
Apply resource import as a controlled migration workflow:
- Inspect the existing resource and reconstruct configuration that matches its actual name, identifiers, and attributes. section 2.2.2
- Copy the configuration into an isolated directory, repository, or state when separating resources from a monolithic configuration. section 10.2.1
- Import the live resource identifiers into the new state, then run a dry run or plan before changing the active infrastructure. section 10.2.1 section 13.3.1
- Confirm that the plan reports no unintended changes; remove the resource from the old configuration and state only after verification. section 10.2.1
- Migrate low-level or independent resources before dependent resources, updating dependencies through dependency injection when necessary. section 10.2.3 section 13.5
Separating IAM resources from a monolith
Copy the IAM configuration into a separate directory, initialize its state, and import the existing service accounts and roles. Run Terraform and verify that the plan reports no changes. Then remove those resources from the monolithic configuration and state, preserving the live infrastructure while completing the refactor. section 10.2.1
