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

TERRAGRUNT_CONFIG env var not considered? #167

Open
cognitiaclaeves opened this issue May 9, 2021 · 2 comments
Open

TERRAGRUNT_CONFIG env var not considered? #167

cognitiaclaeves opened this issue May 9, 2021 · 2 comments
Assignees

Comments

@cognitiaclaeves
Copy link

cognitiaclaeves commented May 9, 2021

I have a repo where I need to maintain separate 'tracks' of config for terragrunt.

Running it looks like this:

export TERRAGRUNT_CONFIG=tg-alt.hcl
terragrunt init

And then in tg-alt.hcl:

terragrunt_version_constraint = ">= 0.29.2"
terraform_version_constraint  = ">= 0.15, < 0.15.2"

I had expected tfswitch to have the same behavior as it does when the above version_constraints are found in terragrunt.hcl.

reference: https://terragrunt.gruntwork.io/docs/getting-started/configuration/#terragrunt-configuration-file

@cognitiaclaeves
Copy link
Author

Reading back through this, I realized I left out a few important details.

After setting up an AWS profile for automation-examples,

git clone [email protected]:cognitiaclaeves/terragrunt-infrastructure-live-example.git
git checkout tfswitch-json
cd tg-alt/acct1/us-east-1/dev/outputs
export TERRAGRUNT_CONFIG=tg-alt.hcl
AWS_PROFILE=automation-examples terragrunt init --terragrunt-source-update

results in:

INFO[0004] Executing hook: tf_ver_b4_switch              prefix=[.]
Terraform v0.15.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.39.0
INFO[0004] Executing hook: tfswitch                      prefix=[.]
Terragrunt file found: /Users/jason/gitrepo/terragrunt-infrastructure-live-example/tg-alt/acct1/us-east-1/dev/outputs/.terragrunt-cache/zawrRJ_hM_7zIiD8UHSWRzTaxRY/sMSf_E1jGYfdJNHr-4YOZ8AbfM4/outputs-only/terragrunt.hcl
Reading required version from constraint: >= 0.15
Matched version: 0.15.3
Switched terraform to version "0.15.3"

This only works because there is a terragrunt.hcl file for the sole purpose of declaring the TF version constraint.
When this is moved, tfswitch fails to find the constraint:

mv terragrunt.hcl terragrunt.hcl_
AWS_PROFILE=automation-examples terragrunt init --terragrunt-source-update

results in:

INFO[0001] Executing hook: tf_ver_b4_switch              prefix=[.]
Terraform v0.15.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.39.0
INFO[0002] Executing hook: tfswitch                      prefix=[.]
Use the arrow keys to navigate: ↓ ↑ → ←
? Select Terraform version:
  ▸ 0.15.3 *recent
    0.15.2
    0.15.1
    0.15.0
↓   0.14.11

The expected behavior would be that tfswitch would recognize the constraint in the tg-alt.hcl file when the TERRAGRUNT_CONFIG env var is set.

@warrensbox
Copy link
Owner

@cognitiaclaeves If I am reading this right, TERRAGRUNT_CONFIG is an environment variable of /path/to/terragrunt.hcl?

@warrensbox warrensbox self-assigned this Jul 14, 2021
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