Bitzu

Terraform Associate 004 ยท Providers and state fundamentals

What is Terraform state and why does it exist?

Mapping config to real objects, metadata, performance, terraform.tfstate contents, why state must be protected and not hand edited (2d).

Key points

  • State: Terraform's record of the real objects it manages.
  • Purpose: maps resource instances to remote objects, stores metadata, improves performance on large infrastructures.
  • Default: JSON file terraform.tfstate in the working directory; previous version in terraform.tfstate.backup.
  • Can contain secrets: protect it, keep it out of version control.
  • Never edit by hand: use terraform state commands.

Source: https://developer.hashicorp.com/terraform/language/state

Practice questions

Single choice

What is the primary purpose of Terraform state?

  1. To keep a history of every command that was run
  2. To store a backup copy of the configuration files
  3. To hold the downloaded provider plugins
  4. To map configuration to the real infrastructure objects
Show answer

Answer: D. To map configuration to the real infrastructure objects

State binds configuration to the real objects Terraform created, so it can compute what to change. It is not a log of commands, a copy of the .tf files, or a cache of provider binaries.

Select all that apply

Which are reasons Terraform keeps state?

  1. To bind resource instances to remote object IDs
  2. To track provider licensing
  3. To record metadata about resources
  4. To make the provider API unnecessary
  5. To store the HCL source code
Show answer

Answer: A. To bind resource instances to remote object IDs, C. To record metadata about resources

State maps config to real objects and keeps metadata, and it speeds up work on large infrastructures. It is not a license manager, and it does not replace the provider's API.

True or false

True or false: it is fine to open terraform.tfstate in an editor and fix resource entries by hand when they look wrong.

Show answer

Answer: False

False. State is a JSON format meant for Terraform; manual edits risk corruption. The terraform state subcommands are the supported way to modify it.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module