Question 1 · choose 2
A team wants one configuration to use a different state bucket for each environment, and tries bucket = var.state_bucket in the backend block, which fails. Which two approaches work? (Choose TWO.)
- AUse a local value for the bucket name instead of an input variable in the backend block
- BSet TF_VAR_state_bucket, which backend blocks can read
- CPut the bucket name in a .tfvars file, which init reads for the backend
- DOmit bucket and pass it with init -backend-config="bucket=..."
- EKeep settings in a file per environment and pass it with -backend-config
Show the answer and why
AUse a local value for the bucket name instead of an input variable in the backend block
Incorrect
A backend block cannot refer to any named values, including locals.
BSet TF_VAR_state_bucket, which backend blocks can read
Incorrect
Backend blocks cannot use input variables, however they are set.
CPut the bucket name in a .tfvars file, which init reads for the backend
Incorrect
Variable definition files set input variables, which backend blocks cannot use.
DOmit bucket and pass it with init -backend-config="bucket=..."
Correct
Omitting arguments gives a partial configuration; the remaining values can be passed to init as key/value pairs.
EKeep settings in a file per environment and pass it with -backend-config
Correct
A file of backend settings can be passed to init with -backend-config=PATH to complete a partial configuration.
Backend settings are read before variables exist; supply the varying parts at init time with partial configuration.
HashiCorp documentation