Bitzu

Terraform Associate 004 ยท State and backends

Protecting state

Secrets in state, encryption at rest, access control, never commit state to VCS, backup and versioning of remote state (6d).

Key points

  • State and plan files can hold secrets in readable form, even for values marked sensitive.
  • Keep state in a remote backend with encryption at rest and tight access control, audit who reads it, and never commit it to version control.
  • Enable versioning or backups on the remote store so a bad write can be rolled back.

Source: https://developer.hashicorp.com/terraform/language/state/sensitive-data

Practice questions

Single choice

A variable is marked sensitive = true. How is its value treated in the state file?

  1. It is still stored in state and readable by anyone who can read the file
  2. It is automatically encrypted inside the state file
  3. It is removed from state after apply finishes
  4. It is replaced with asterisks in the state file
Show answer

Answer: A. It is still stored in state and readable by anyone who can read the file

Sensitive only hides the value in CLI output. It is still written to state and plan files, readable by anyone with access to them.

Select all that apply

Which measures help protect Terraform state?

  1. Use a remote backend that encrypts state at rest
  2. Restrict who can read state and keep audit logs of access
  3. Exclude state files from Git workflows, for example via .gitignore
  4. Print the full state in CI logs for easier debugging
  5. Share the state file in team chat when someone needs it
Show answer

Answer: A. Use a remote backend that encrypts state at rest, B. Restrict who can read state and keep audit logs of access, C. Exclude state files from Git workflows, for example via .gitignore

Encrypting at rest, limiting access with audit logs and keeping state out of Git are all recommended. Printing state in CI logs and sharing the file by chat widen exposure.

True or false

True or false: it is safe to commit terraform.tfstate to a private Git repository, because the sensitive keyword encrypts its secrets.

Show answer

Answer: False

False. Sensitive does not encrypt anything in state, and state should be excluded from version control regardless of repository visibility.

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