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

Support for -var or -var-file arguments #1

Closed
fogers777 opened this issue Nov 29, 2022 · 2 comments
Closed

Support for -var or -var-file arguments #1

fogers777 opened this issue Nov 29, 2022 · 2 comments

Comments

@fogers777
Copy link

we have value of variable which we pass from gitlab secrets and running tftree it requires it and tftree fails.

➜  git: ✗ tftree 
Running "terraform init"... 
Running "terraform plan"... 
╷
│ Error: 
│
│ Command "/Users/bin/terraform" with args ["terraform" "plan" "-out" "/var/folders/dl/slnh1vrd4nq2fs6r6vz2fqg40000gn/T/tftree.93526139.plan"] failed: exit status 1
│ Command output:
│ var.apikey
│   (required) API key
│
│   Enter a value: ╷
│ │ Error: No value for required variable
│ │ 
│ │   on _variables.tf line 1:
│ │    1: variable "apikey" {
│ │ 
@busser
Copy link
Owner

busser commented Nov 30, 2022

Hi @fogers777, thanks for coming forward!

This is already possible, although I admit it should be documented. My bad.

Terraform supports setting variables in the environment. For example, to set the foo variable to bar:

TF_VAR_foo=bar tftree

Similarly, you can set flags for specific commands. To use the -var-file flag:

TF_CLI_ARGS_plan="-var-file=production.tfvars" tftree

The complete list of available environment variables is in Terraform's documentation here: https://developer.hashicorp.com/terraform/cli/config/environment-variables

I hope this solves your issue. Let me know if it does 🙂

@fogers777
Copy link
Author

Thank you @busser, got it working now ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants