Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Var file is not applied to init #355

Open
autarchprinceps opened this issue Nov 19, 2024 · 3 comments
Open

Var file is not applied to init #355

autarchprinceps opened this issue Nov 19, 2024 · 3 comments
Labels
defect Something isn't working

Comments

@autarchprinceps
Copy link

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.

@autarchprinceps
Copy link
Author

I assume the same will likely be true for tofu-apply, but as we create a plan first to approve what tofu is going to do, I can't easily test that

@dflook dflook transferred this issue from dflook/tofu-plan Nov 20, 2024
@dflook
Copy link
Owner

dflook commented Nov 20, 2024

This is releated to the Early Evaluation feature in OpenTofu 1.8

@dflook dflook added the defect Something isn't working label Nov 20, 2024
@autarchprinceps
Copy link
Author

Are you planning to support this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants