0
0
Terraformcloud~10 mins

Import state verification in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Import state verification
Identify existing resource
Run terraform import command
Terraform maps resource to state
Verify imported state matches resource
Use terraform plan to confirm no changes
Done
This flow shows how Terraform imports an existing resource into its state and verifies it matches the real resource.
Execution Sample
Terraform
terraform import aws_s3_bucket.mybucket my-existing-bucket
terraform plan
Imports an existing AWS S3 bucket into Terraform state and then checks for any differences.
Process Table
StepActionInput/CommandTerraform StateResult/Output
1Identify resourceExisting S3 bucket 'my-existing-bucket'State empty for aws_s3_bucket.mybucketReady to import
2Run importterraform import aws_s3_bucket.mybucket my-existing-bucketState updated with bucket infoResource mapped to state
3Verify stateterraform planState has aws_s3_bucket.mybucketNo changes detected, state matches resource
4End-State stableImport and verification complete
💡
Status Tracker
VariableStartAfter Step 2After Step 3Final
aws_s3_bucket.mybucketNot in stateImported with bucket attributesVerified matches resourceStable in state
Key Moments - 2 Insights
Why does terraform plan show no changes after import?
Because the imported state matches the actual resource configuration, terraform plan confirms no drift (see execution_table step 3).
What happens if the resource does not exist when running terraform import?
Terraform import will fail and state will not update, so no resource is mapped (refer to 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?
AState updated with bucket info
BState is empty
CState shows errors
DState removed the resource
💡 Hint
Check execution_table row 2 under 'Terraform State'
At which step does terraform confirm that the imported resource matches the actual resource?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at execution_table row 3 under 'Result/Output'
If the resource did not exist, what would happen to the state after step 2?
AState would be updated with partial info
BState would remain empty
CState would contain errors but resource added
DState would remove all resources
💡 Hint
Refer to key_moments about import failure and execution_table step 2
Concept Snapshot
terraform import <resource> <id>
Maps existing resource to Terraform state.
Run terraform plan to verify no changes.
If plan shows no changes, import succeeded.
If resource missing, import fails with error.
Full Transcript
Import state verification in Terraform involves identifying an existing resource, running the terraform import command to map it into Terraform's state file, and then verifying the import by running terraform plan. The plan should show no changes if the state matches the actual resource. If the resource does not exist, the import command fails and the state remains unchanged. This process ensures Terraform can manage existing infrastructure without recreating it.