tfenv icon indicating copy to clipboard operation
tfenv copied to clipboard

Consider adding option to configure tf global options, or `-chdir` specifically

Open OJFord opened this issue 4 years ago • 1 comments

We've ended up with two duplicate/conflicting lock files where people have variously used:

terraform init subdir
cd subdir && terraform init

The -chdir=subdir 'global option' could help avoid this, but nobody wants to type that out every time.

Unfortunately it's only valid before the subcommand, and $TF_CLI_ARGS puts its args after the subcommand (since currently all other args are only valid in that position anyway) (https://github.com/hashicorp/terraform/issues/22734#issuecomment-788865551).

Since this is a per-repository issue anyway, it would make sense to me if this could be handled through tfenv, i.e. the terraform wrapper would provide something like:

real_terraform -chdir="${tfdir:-.}" $@

OJFord avatar Mar 02 '21 12:03 OJFord

My related PR #303 fixes problems using -chdir with tfenv's terraform wrapper - but note that doesn't close this. My suggestion here was that a tfenv configuration could be the source of the 'chdir', so that it can be shared with colleagues in a checked-in file along with the tf version. (And you'd just run terraform and have tfenv find the correct version & -chdir arg.)

Implementation-wise, it does mean that the -chdir resolution would have to happen prior to version, since a min-required version requires knowing where the HCL files are.

OJFord avatar Oct 26 '21 16:10 OJFord