busser / tftree

Display your Terraform module call stack in your terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for -var or -var-file arguments

fogers777 opened this issue · comments

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" {
│ │ 

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 🙂

Thank you @busser, got it working now ;)