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
What is the primary purpose of Terraform state?
- To keep a history of every command that was run
- To store a backup copy of the configuration files
- To hold the downloaded provider plugins
- 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.
Which are reasons Terraform keeps state?
- To bind resource instances to remote object IDs
- To track provider licensing
- To record metadata about resources
- To make the provider API unnecessary
- 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: 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.
