0
0
Terraformcloud~10 mins

Bulk import strategies in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Bulk import strategies
Identify resources to import
Prepare import commands list
Run terraform import for each resource
Verify imported state
Write resource blocks in config
Run terraform plan to confirm sync
Done
This flow shows how to import many resources into Terraform state step-by-step, from identifying resources to confirming they are managed.
Execution Sample
Terraform
terraform import aws_instance.example i-1234567890abcdef0
terraform import aws_s3_bucket.example my-bucket-name
These commands import an AWS EC2 instance and an S3 bucket into Terraform state.
Process Table
StepActionResourceCommandResult
1Identify resourcesEC2 instance-Found instance i-1234567890abcdef0
2Identify resourcesS3 bucket-Found bucket my-bucket-name
3Prepare import commandsEC2 instanceterraform import aws_instance.example i-1234567890abcdef0Ready to import
4Prepare import commandsS3 bucketterraform import aws_s3_bucket.example my-bucket-nameReady to import
5Run importEC2 instanceterraform import aws_instance.example i-1234567890abcdef0Imported successfully
6Run importS3 bucketterraform import aws_s3_bucket.example my-bucket-nameImported successfully
7Verify stateAllterraform state listResources listed in state
8Write configAllWrite resource blocks in .tf filesConfig matches imported resources
9Run planAllterraform planNo changes, state and config in sync
10Done--Bulk import complete
💡 All resources imported and Terraform state matches configuration
Status Tracker
VariableStartAfter Step 5After Step 7After Step 9Final
terraform stateemptycontains EC2 and S3verified resources listedmatches configstable and synced
configuration filesemptyemptyemptyresource blocks addedcomplete
Key Moments - 3 Insights
Why do we need to write resource blocks in config after importing?
Because terraform import only adds resources to state, but config files must define resources for Terraform to manage them. See execution_table step 8.
What happens if the resource ID is wrong during import?
The import command will fail and not add the resource to state. You must use the correct ID as shown in steps 3 and 4.
Why run terraform plan after import and writing config?
To confirm that the imported state matches the config and no unexpected changes will occur. See step 9.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of running 'terraform import' for the EC2 instance at step 5?
AImport failed
BImported successfully
CResource not found
DNo changes detected
💡 Hint
Check the 'Result' column at step 5 in the execution_table.
At which step do we verify that the Terraform state lists all imported resources?
AStep 3
BStep 9
CStep 7
DStep 2
💡 Hint
Look for the step with action 'Verify state' in the execution_table.
If you skip writing resource blocks in config, what will happen when you run 'terraform plan'?
ATerraform will try to delete imported resources
BTerraform will error due to missing config
CTerraform will show no changes
DTerraform will import resources again
💡 Hint
Refer to key_moments about why config is needed after import and step 9 in execution_table.
Concept Snapshot
Bulk import in Terraform:
1. Identify existing resources.
2. Prepare and run 'terraform import' commands.
3. Write matching resource blocks in config files.
4. Run 'terraform plan' to confirm state and config sync.
Always import before writing config to avoid conflicts.
Full Transcript
Bulk import strategies in Terraform involve identifying existing cloud resources, preparing import commands for each, running these commands to add resources to Terraform state, then writing resource blocks in configuration files to manage them. After importing and writing config, running 'terraform plan' confirms that the state and config are synchronized with no unexpected changes. This process ensures Terraform can manage existing infrastructure safely and effectively.