Back to interview
interview#terraform#state#interview

How does Terraform know what already exists?

The most missed Terraform interview follow-up. Explain state files and how they work.

Jane Contributor August 2, 2026 2 views
interview_qa.md

Question

How does Terraform know what infrastructure already exists in the cloud?

Answer

Terraform keeps a **state file** (`terraform.tfstate`) that maps every resource in your `.tf` files to its real-world identifier (an AWS ARN, an Azure resource ID, etc.). On `terraform plan`, Terraform reads the state, calls the cloud APIs to refresh each resource's current attributes, and diffs them against your configuration to compute the plan. In a team setting you **must not keep state on your laptop** — you configure a **remote backend** (S3 + DynamoDB lock for AWS, Azure Storage for Azure, GCS for GCP) so everyone reads and writes the same state, and DynamoDB/blob leases prevent two people applying at the same time. If you lose the state file, Terraform will try to create the resources again — potentially causing duplicates or conflicts.

See the question and answer above.

Keep reading

You may also like

Discussion (0)

No comments yet. Be the first to weigh in.

Leave a comment

Comments are reviewed before appearing.