What is the Terraform state file used for?
- To store Terraform source code
- To cache terraform plans
- To track the current state of managed infrastructure ✓
- To define provider configurations
Correct answer: To track the current state of managed infrastructure
Option C is correct because the Terraform state file (terraform.tfstate) records the current real-world state of all resources Terraform manages, mapping configuration to actual infrastructure so Terraform can determine what changes to apply on the next run. Option A is wrong because source code is stored in .tf configuration files, not the state file. Option B is wrong because plan output is a separate artifact (terraform.tfplan) and is not cached in the state file. Option D is wrong because provider configurations, including credentials and version constraints, are declared in .tf files, not the state file.
Topic: · terraform, state management, infrastructure as code, terraform state