How Do You Troubleshoot Terraform Commands That Do Not Seem to Use the -var-file= Flag Passed to Them?

Problem scenario
You want to pass the var-file flag in a Terraform command. You have a different configuration/variables file (from the default one) that you want the Terraform command to use. The resulting error indicates that there is insuffient configuration data; the behavior is consistent with no variables files being readable.

How do you get a terraform plan command to look at a different folder location or directory?

Possible Solution #1
Are you in the correct directory when you run the terraform plan command? Are you in a hidden directory? Can you change (cd) to the directory with the .tfvars file? Can you run terraform init again from this directory?

(This solution was adapted from this devops.stackexchange.com posting.)


Possible Solution #2
What are the files of the .tfvars file? Can you run ls -lh foobar.tfvars? Perhaps the file is not readable for the user running the Terraform command.

Leave a comment

Your email address will not be published. Required fields are marked *