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 fails when tfenv install is run #3506

Open
2 tasks
mazay opened this issue Oct 21, 2024 · 3 comments
Open
2 tasks

Terragrunt fails when tfenv install is run #3506

mazay opened this issue Oct 21, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mazay
Copy link

mazay commented Oct 21, 2024

Describe the bug

Terragrunt can't parse terraform --version output when desired Terrraform version is not yet installed in the running envirenment.

Steps To Reproduce

  1. Have a Terragrunt module with .terraform-version file
  2. Make sure the Terraform version is not yet installed - tfenv uninstall
  3. Run any Terragrunt command and observe the following debug output:
$ terragrunt init --terragrunt-log-level debug --terragrunt-debug
14:50:43.227 DEBUG  Terragrunt Version: 0.68.4
14:50:43.231 DEBUG  Found locals block: evaluating the expressions.
14:50:43.231 DEBUG  Evaluated 2 locals (remaining 0): common_vars, env_vars
14:50:43.233 DEBUG  Found locals block: evaluating the expressions.
14:50:43.234 DEBUG  [../..] Found locals block: evaluating the expressions.
14:50:43.234 DEBUG  [../..] Evaluated 1 locals (remaining 0): region
14:50:43.234 DEBUG  [../..] Found locals block: evaluating the expressions.
14:50:43.234 DEBUG  [../..] Evaluated 1 locals (remaining 0): region
14:50:43.235 DEBUG  [../../..] Found locals block: evaluating the expressions.
14:50:43.235 DEBUG  [../../..] Evaluated 4 locals (remaining 1): env, route53_zone_id, tfstate_bucket, tfstate_bucket_region
14:50:43.235 DEBUG  [../../..] Evaluated 1 locals (remaining 0): tags
14:50:43.235 DEBUG  [../../..] Found locals block: evaluating the expressions.
14:50:43.235 DEBUG  [../../..] Evaluated 4 locals (remaining 1): env, route53_zone_id, tfstate_bucket, tfstate_bucket_region
14:50:43.235 DEBUG  [../../..] Evaluated 1 locals (remaining 0): tags
14:50:43.235 DEBUG  Evaluated 5 locals (remaining 2): region_vars, app_vars, resource_vars, common_vars, env_vars
14:50:43.235 DEBUG  Evaluated 2 locals (remaining 0): tfstate_bucket, tfstate_bucket_region
14:50:43.236 DEBUG  [Partial] Included config ../../../../terragrunt.hcl has strategy shallow merge: merging config in (shallow).
14:50:43.236 DEBUG  Running command: terraform --version
14:50:43.236 DEBUG  Engine is not enabled, running command directly in .
14:50:46.616 ERROR  Unable to parse Terraform version output: version '1.2.0' is not installed (set by ./.terraform-version). Installing now as TFENV_AUTO_INSTALL==true
Installing Terraform v1.2.0
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.0/terraform_1.2.0_darwin_arm64.zip
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.2.0/terraform_1.2.0_SHA256SUMS
Not instructed to use Local PGP (/opt/homebrew/Cellar/tfenv/3.0.0/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /var/folders/fr/mykfk5yn6yz3jl9pflw9w4wh0000gq/T/tfenv_download.XXXXXX.H36KunNCdZ/terraform_1.2.0_darwin_arm64.zip
  inflating: /opt/homebrew/Cellar/tfenv/3.0.0/versions/1.2.0/terraform
Installation of terraform v1.2.0 successful. To make this your default version, run 'tfenv use 1.2.0'
Terraform v1.2.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.45.0

Your version of Terraform is out of date! The latest version
is 1.9.8. You can update by downloading from https://www.terraform.io/downloads.html

14:50:46.742 DEBUG  terraform.InvalidTerraformVersionSyntax Unable to parse Terraform version output: version '1.2.0' is not installed (set by ./.terraform-version). Installing now as TFENV_AUTO_INSTALL==true
Installing Terraform v1.2.0
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.0/terraform_1.2.0_darwin_arm64.zip
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.2.0/terraform_1.2.0_SHA256SUMS
Not instructed to use Local PGP (/opt/homebrew/Cellar/tfenv/3.0.0/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /var/folders/fr/mykfk5yn6yz3jl9pflw9w4wh0000gq/T/tfenv_download.XXXXXX.H36KunNCdZ/terraform_1.2.0_darwin_arm64.zip
  inflating: /opt/homebrew/Cellar/tfenv/3.0.0/versions/1.2.0/terraform
Installation of terraform v1.2.0 successful. To make this your default version, run 'tfenv use 1.2.0'
Terraform v1.2.0
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v5.45.0

Your version of Terraform is out of date! The latest version
is 1.9.8. You can update by downloading from https://www.terraform.io/downloads.html

/home/circleci/project/cli/commands/terraform/version_check.go:181 (0x1059ba831)
/home/circleci/project/cli/commands/terraform/version_check.go:102 (0x1059ba2e0)
/home/circleci/project/cli/commands/terraform/version_check.go:55 (0x1059ba048)
/home/circleci/project/cli/commands/terraform/action.go:97 (0x1059b1d6c)
/home/circleci/project/cli/commands/terraform/action.go:83 (0x1059b1c4c)
/home/circleci/project/cli/commands/terraform/command.go:47 (0x106039e28)
/home/circleci/project/cli/app.go:235 (0x10603b638)
/home/circleci/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:78 (0x1054bb144)
/usr/local/go/src/runtime/asm_arm64.s:1223 (0x10442f6e4)

14:50:46.743 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1

The issue is reproducible starting with TG versions 0.57.12.

Expected behavior

With versions 0.57.11 and older tfenv installs the desired TF version and TG can properly parse the output.

Nice to haves

  • Terminal output
  • Screenshots

Versions

  • Terragrunt version: 0.68.4
  • OpenTofu/Terraform version: any
  • Environment details (Ubuntu 20.04, Windows 10, etc.): any

Additional context

We use tfenv and tgenv for maintaining our TF and TG versions, we heavily rely on this in our deployments pipelines as module A can depend on module B and they can use different TF versions. With tfenv we can easily and seamlessly install required TF version when running terragrunt run-all commands, unfortunately, this functionality is broken now.

@mazay mazay added the bug Something isn't working label Oct 21, 2024
@denis256
Copy link
Member

It looks like is an issue with the parsing of the Terraform version when tfenv downloads it

@gcavalcante8808
Copy link

I believe that I'm seeing the same behavior with tofuenv:

13:00:01.996 STDOUT tofu: version '# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
13:00:01.996 STDOUT tofu: 1.8.3' is not installed (set by /var/home/arthas/PycharmProjects/gaia/gaia-infrastructure/Cloud/github_repositories/n8n/.terragrunt-cache/j_qGdkEcKiUlPUS-zdmgdQ2KMos/gIpGX31kln3QFgEXq1HZBiKjwO0/modules/services/github/.opentofu-version). Installing now as TOFUENV_AUTO_INSTALL==true
13:00:04.830 STDOUT tofu: OpenTofu v1.8.3 is already installed
13:00:04.839 STDERR tofu: /var/home/linuxbrew/.linuxbrew/Cellar/tofuenv/1.0.6/lib/tofuenv-exec.sh: line 43: /var/home/linuxbrew/.linuxbrew/Cellar/tofuenv/1.0.6/versions/# Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa
13:00:04.839 STDERR tofu: 1.8.3/tofu: No such file or directory
13:00:04.840 ERROR  tofu invocation failed in ./.terragrunt-cache/j_qGdkEcKiUlPUS-zdmgdQ2KMos/gIpGX31kln3QFgEXq1HZBiKjwO0/modules/services/github
13:00:04.840 DEBUG  Copying lock file from ./.terragrunt-cache/j_qGdkEcKiUlPUS-zdmgdQ2KMos/gIpGX31kln3QFgEXq1HZBiKjwO0/modules/services/github/.terraform.lock.hcl to .
13:00:04.841 ERROR  error occurred:

Any news on this?

@mwos-sl
Copy link

mwos-sl commented Nov 25, 2024

Hitting the same in the newest terragrunt (0.69.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants