Practice Terraform state vocabulary: state file tracking, remote state backends, DynamoDB locking, state corruption recovery, terraform state mv, drift detection, and importing existing resources.
0 / 5 completed
1 / 5
'The state file tracks all managed resources.' What happens if the state file is deleted?
The Terraform state file is the single source of truth about what infrastructure Terraform manages. Without it, Terraform doesn't know what it previously created. Running terraform apply without state would create duplicate resources (since Terraform thinks nothing exists). This is why remote state with backup is critical for any real infrastructure.
2 / 5
'Remote state in S3 with DynamoDB locking.' Why is DynamoDB locking needed?
When the state file is stored in S3, multiple team members could potentially run terraform apply at the same time — both reading the same state, both making changes, and both writing back a new state file, causing one to overwrite the other (state corruption). DynamoDB provides a distributed lock: the first apply operation acquires the lock, and any concurrent apply waits or fails with a lock error.
3 / 5
'Terraform state mv to reorganise resources.' What does terraform state mv do?
terraform state mv changes how a resource is addressed in the state file. For example, if you rename an AWS instance from aws_instance.web to aws_instance.frontend, terraform state mv aws_instance.web aws_instance.frontend updates the state reference so Terraform doesn't destroy the old resource and create a new one. It's essential for safe refactoring of Terraform code.
4 / 5
'The plan shows infrastructure drift.' What is infrastructure drift in Terraform?
Infrastructure drift occurs when cloud resources are modified outside of Terraform — by someone manually changing settings in the console, or by other automation tools. Running terraform plan detects drift by comparing the actual resource state (fetched from the provider) against what Terraform expects from its state and configuration. Drift appears as 'will be updated' or 'will be replaced' in the plan output.
5 / 5
'We import existing infrastructure into state.' When is terraform import used?
terraform import allows Terraform to begin managing infrastructure that was created outside of Terraform. You write the resource configuration block, then run terraform import to associate the existing cloud resource (identified by its provider ID) with that configuration in the state. After import, terraform plan should show no changes if the configuration matches the actual resource.