0
0
Terraformcloud~10 mins

Why importing existing resources matters in Terraform - Visual Breakdown

Choose your learning style9 modes available
Process Flow - Why importing existing resources matters
Start: Existing Cloud Resource
Terraform Config Created
Import Command Runs
Terraform State Updated
Terraform Plan & Apply
Manage Resource with Terraform
This flow shows how an existing cloud resource is linked to Terraform by importing it into Terraform's state, allowing Terraform to manage it.
Execution Sample
Terraform
terraform import aws_instance.example i-1234567890abcdef0
terraform plan
terraform apply
This code imports an existing AWS instance into Terraform state, then plans and applies changes.
Process Table
StepActionTerraform StateResult
1Run import commandEmptyResource details added to state
2Terraform planState includes resourceShows no changes if config matches
3Terraform applyState updated if changesResource managed by Terraform
4Modify resource outside TerraformState unchangedPlan shows drift on next run
5Re-import or update configState updatedTerraform syncs with actual resource
💡 Import links existing resource to Terraform state so it can be managed.
Status Tracker
VariableStartAfter ImportAfter PlanAfter ApplyAfter External ChangeAfter Sync
terraform_stateemptyresource addedmatches configmanaged resourceout of syncupdated to match
Key Moments - 3 Insights
Why can't Terraform manage a resource before importing it?
Terraform only manages resources listed in its state. Before import, the resource exists but is unknown to Terraform (see execution_table step 1).
What happens if the resource changes outside Terraform after import?
Terraform state does not auto-update. Plan will detect drift and show differences (execution_table step 4). You must re-import or update config to sync.
Why run terraform plan after import?
Plan checks if the imported resource matches the config. If they differ, plan shows changes to apply (execution_table step 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the terraform_state after running the import command?
AEmpty
BManaged resource
CResource details added to state
DOut of sync
💡 Hint
Check execution_table row 1 under Result column.
At which step does Terraform detect changes made outside of Terraform?
AStep 4 - Modify resource outside Terraform
BStep 3 - Terraform apply
CStep 2 - Terraform plan
DStep 5 - Re-import or update config
💡 Hint
Look at execution_table row 4 describing external changes.
If you skip the import step, what will Terraform state be when managing an existing resource?
AManaged resource
BEmpty
CResource details added
DOut of sync
💡 Hint
Refer to execution_table step 1 showing state before import.
Concept Snapshot
Terraform import links existing cloud resources to Terraform state.
Without import, Terraform doesn't know about existing resources.
Import updates state so Terraform can manage the resource.
Plan shows differences between config and actual resource.
Apply enforces config changes.
Re-import or update config to sync after external changes.
Full Transcript
Importing existing resources matters because Terraform manages only what it knows in its state file. When you create resources outside Terraform, they are not tracked. Running 'terraform import' adds these resources to the state, letting Terraform manage them. After import, running 'terraform plan' checks if the resource matches your Terraform configuration. If they differ, plan shows changes to apply. Applying enforces these changes. If the resource changes outside Terraform later, the state becomes out of sync. You must re-import or update your configuration to keep Terraform in sync. This process ensures Terraform can safely manage all resources, avoiding conflicts or accidental deletions.