Skip to content

Var file is not applied to init #355

Closed
@autarchprinceps

Description

@autarchprinceps

Despite running the tofu-plan with a var file setting:
image
It fails at not having variables set in the initialisation, which is essential for backend configuration dependent on the environment:

Initializing OpenTofu
  Initializing the backend...
  Initializing modules...
...
  ╷
  │ Error: Unable to compute static value
  │ 
  │   on provider.tf line 28, in terraform:
  │   28:   backend "s3" {
  │ 
  │ backend.s3 depends on var.account_id which is not available
  ╵
  
  ╷
  │ Error: Unable to compute static value
  │ 
  │   on provider.tf line 28, in terraform:
  │   28:   backend "s3" {
  │ 
  │ backend.s3 depends on var.account_id which is not available
  ╵
  
  ╷
  │ Error: Unable to compute static value
  │ 
  │   on provider.tf line 28, in terraform:
  │   28:   backend "s3" {
  │ 
  │ backend.s3 depends on var.env which is not available
  ╵
  
  ╷
  │ Error: Variable not provided via -var, tfvars files, or env
  │ 
  │   on variables.tf line 4:
  │    4: variable "env" {
  │ 
  ╵
  
  ╷
  │ Error: Variable not provided via -var, tfvars files, or env
  │ 
  │   on variables.tf line 29:
  │   29: variable "account_id" {
  │ 
  ╵
  
  ╷
  │ Error: Variable not provided via -var, tfvars files, or env
  │ 
  │   on variables.tf line 29:
  │   29: variable "account_id" {
  │ 
  ╵

Manually running a tofu init -var-file=../vars/preprod.tfvars followed by the same for plan or apply on the other hand works without issue. Paths are correct, I double checked that. I think it just provides the vars to the apply step, which may be enough for some cases, but far from all, and providing it to init doesn't hurt in those either, but failing to do so makes it unusable for anybody configuring something like this example, where different vars point to different state buckets for example, because they are in different accounts, as is best practice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions