0
0
Terraformcloud~10 mins

Terraform import command - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Terraform import command
Start: Existing Resource
Run terraform import
Terraform maps resource to state
State file updated
Terraform can now manage resource
End
The terraform import command links an existing resource to Terraform's state, allowing Terraform to manage it.
Execution Sample
Terraform
terraform import aws_instance.example i-1234567890abcdef0
Imports an existing AWS EC2 instance with ID i-1234567890abcdef0 into Terraform state as aws_instance.example.
Process Table
StepActionInputTerraform State ChangeResult
1Identify existing resourceAWS EC2 instance ID i-1234567890abcdef0No change yetReady to import
2Run terraform import commandterraform import aws_instance.example i-1234567890abcdef0Maps aws_instance.example to resource IDState file updated with resource
3Terraform state updatedResource linked in state fileState file now tracks aws_instance.exampleTerraform can manage resource
4Verify importterraform planChecks resource matches configurationNo changes if config matches
5ExitImport completeState file updatedTerraform manages existing resource
💡 Import completes when resource is linked in Terraform state and ready for management.
Status Tracker
VariableStartAfter Step 2After Step 3Final
Terraform StateEmpty or without resourceResource aws_instance.example mappedState file updated with resource detailsState tracks aws_instance.example
Key Moments - 3 Insights
Why doesn't terraform import create a resource?
Terraform import only links existing resources to the state; it does not create or modify resources. See execution_table step 2 where the resource is mapped but not created.
What happens if the Terraform configuration does not match the imported resource?
Terraform plan after import (step 4) will show differences and may propose changes to match the configuration.
Does terraform import update the configuration files?
No, terraform import only updates the state file. Configuration files must be written manually to match the imported resource.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the Terraform state file updated?
AStep 1
BStep 4
CStep 2
DStep 5
💡 Hint
Check the 'Terraform State Change' column in execution_table rows.
According to variable_tracker, what is the state of Terraform State after step 3?
AState file updated with resource details
BResource aws_instance.example mapped
CEmpty or without resource
DState tracks aws_instance.example
💡 Hint
Look at the 'After Step 3' column for Terraform State in variable_tracker.
If the configuration file does not match the imported resource, what will terraform plan show?
ANo changes
BProposed changes to match configuration
CError and stops
DDeletes the resource
💡 Hint
Refer to key_moments about what happens after import when config differs.
Concept Snapshot
terraform import <resource> <id>

Links an existing resource to Terraform state.
Does NOT create or modify resources.
Updates state file only.
Configuration files must match resource manually.
Run terraform plan to verify after import.
Full Transcript
The terraform import command is used to bring an existing cloud resource under Terraform management by linking it to the Terraform state file. It does not create or change the resource itself. The process starts by identifying the existing resource, then running the import command with the resource address and ID. Terraform updates its state file to track the resource. After import, running terraform plan helps verify if the configuration matches the imported resource. If there are differences, Terraform will propose changes. Import only affects the state file; configuration files must be written manually to reflect the resource. This allows Terraform to manage resources created outside Terraform.