Bitzu

Terraform Associate 004 ยท State and backends

Remote state with the backend block

backend block inside terraform block, example backends (s3, azurerm, gcs, remote/cloud), partial configuration, no variables in backend blocks (6c).

Key points

  • Declare backend "type" { ... } inside the terraform block (for example s3, azurerm, gcs or the remote/cloud options).
  • Only one backend block is allowed and it must be literal: no variables, locals or data.
  • Use partial configuration to supply the rest at init with -backend-config, and keep credentials in environment variables.

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

Practice questions

Single choice

Where in a configuration is a backend block declared?

  1. Inside the terraform block
  2. Inside a provider block
  3. Inside a resource block
  4. Inside a variable block
Show answer

Answer: A. Inside the terraform block

Backend configuration is nested inside the top-level terraform block. It is not a resource, provider or variable.

Select all that apply

Which statements about partial backend configuration are correct?

  1. Required arguments can be left out of the block and given at init
  2. At least an empty block naming the backend type is still needed
  3. Values given on the command line override the main configuration
  4. Input variables can be used to fill the missing arguments
  5. Passing secrets as KEY=VALUE is the recommended method
Show answer

Answer: A. Required arguments can be left out of the block and given at init, B. At least an empty block naming the backend type is still needed, C. Values given on the command line override the main configuration

Required arguments may be omitted and supplied at init, an empty backend block still names the type, and command-line values override the file. Variables are not allowed, and passing secrets as KEY=VALUE is discouraged because of shell history.

True or false

True or false: a backend block can read values from input variables, as long as the variables have default values.

Show answer

Answer: False

False. Backend blocks cannot use named values such as input variables, locals or data source attributes, with or without defaults.

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