idoavrah / terraform-tui

Terraform textual UI
https://pypi.org/project/tftui/
Apache License 2.0
973 stars 30 forks source link

Add support for TF_VAR_<VALUE> #73

Closed jz-wilson closed 1 month ago

jz-wilson commented 1 month ago

Hi, looking adding support for using TF_VAR_<VALUE> for variables used as from sourced environment variables. It seems like the sourced variables are not making into tftui.

I am currently using a Makefile to do this:

$(TASKS):
    . ${HOME}/.terraform/defaults/_$(ENV) && terraform $@ -var-file=env/$(ENV)/$(WS_REGION)/terraform.tfvars $(foreach var,$(TARGETS),-target=$(var)) $(ARGS)

I would just create a .tfvar file, but I don't need all the variables everytime.

Awesome work on this application btw!

idoavrah commented 1 month ago

Hi Johnzell,

I actually never used this feature in terraform and wasn't aware of it. That being said, I did some tests and it seems that env vars do transfer to the tftui process (and through it to the terraform plan command that is executed within the application itself). Are you sure you're exporting those environment variables and not just setting them so that they'll be inherited by child processes?

Can you elaborate on the specific process you're going through so I can and duplicate it on my end?

jz-wilson commented 1 month ago

Nope, I wasn't exporting them...

I have a bash script that would set the env vars, but I didn't set the export on them.

Thanks.

I'm running this:

. ~/.terraform/defaults/.dev && tftui -f env/dev/us-east-2/terraform.tfvars

This worked for me.

idoavrah commented 1 month ago

Glad I could help :)