Interview Prep/Terraform/Variables, Locals, Outputs and Types

Can you use variables in the backend block?

IntermediateConceptVariables, Locals, Outputs and Types
Answer

No. Backend configuration is read before variables are evaluated, so var. references fail. Use partial configuration with terraform init -backend-config=... and a per-environment file instead. OpenTofu 1.8 added early evaluation, allowing variables and locals in backend and module source arguments.

All Terraform questions Roadmap: Terraform

More on Variables, Locals, Outputs and Types