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
Where in a configuration is a backend block declared?
- Inside the terraform block
- Inside a provider block
- Inside a resource block
- 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.
Which statements about partial backend configuration are correct?
- Required arguments can be left out of the block and given at init
- At least an empty block naming the backend type is still needed
- Values given on the command line override the main configuration
- Input variables can be used to fill the missing arguments
- 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: 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.
