What is the Terraform state file used for?

  1. To store Terraform source code
  2. To cache terraform plans
  3. To track the current state of managed infrastructure ✓
  4. 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

Practice HashiCorp Terraform Associate (003) Questions Free