pwillis-els / terraformsh

A wrapper for Terraform in Bash
MIT License
66 stars 12 forks source link

when `USE_PLANFILE=0` variables are not passed to apply or destroy #26

Closed bdellegrazie closed 1 year ago

bdellegrazie commented 1 year ago

Hi,

Firstly - great tool - thank you very much.

Problem Description

When the use of plan files is disabled (USE_PLANFILE=0) the terraformsh apply doesn't include the variable files picked up from the configuration tree (default or otherwise).

Configuration

In our specific situation we're trying to mimic stock Terraform behaviour. For this reason our .terraformshrc in the config tree looks like this: .terraformrc:

USE_PLANFILE=0
NO_DEP_CMDS=1
NO_CLEANUP_TMP=1
export TF_DATA_DIR="${PWD}/.terraform"
CD_DIR=<relative_path_to_root_module>

Expected behaviour

When running terraformsh apply (or terraformsh destroy) in the config tree I expect:

terraform apply -var-file <path-to-config-dir>/terraform.sh.tfvars -input=false

Observed behaviour

When running terraformsh apply in the config tree I get:

❯ terraformsh apply
<path_to_>/terraformsh: Info: Found terraform command 'apply'
+ cd "<module_path>"
+ terraform apply -input=false

Note the missing -var-file entry?

Notes

Looking at the difference between the implementation of terraform plan vs terraform apply I can see that "${VARFILE_ARG[@]}" is missing from terraform apply. Adding this to my local copy works but I suspect that you only want this when USE_PLANFILE=0 so it should probably be conditional.

The same issue exists for destroy and likely other commands (when appropriate to supply tfvars)

pwillis-els commented 1 year ago

Sorry this took so long to get to!! Thanks very much for your contribution 🙏 I've merged your change!