gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.09k stars 981 forks source link

terragrunt console broken #3507

Closed nvigot closed 3 weeks ago

nvigot commented 3 weeks ago

Describe the bug

terragrunt console has stopped working since commit afd5d7f962bd1e651f04a44968342ed1642a8e8e. Release v0.68.0-beta2024100702 is the latest working version.

Steps To Reproduce

Run terragrunt console on Linux/macOS

$ terragrunt §
17:39:36.859 DEBUG  Terragrunt Version: 0.68.4
17:39:36.862 DEBUG  Did not find any locals block: skipping evaluation.
17:39:36.863 DEBUG  Running command: terraform --version
17:39:36.863 DEBUG  Engine is not enabled, running command directly in .
17:39:36.909 DEBUG  terraform version: 1.8.5
17:39:36.910 DEBUG  Reading Terragrunt config file at ./terragrunt.hcl
17:39:36.911 DEBUG  Did not find any locals block: skipping evaluation.
17:39:36.913 DEBUG  Did not find any locals block: skipping evaluation.
17:39:36.916 DEBUG  terraform files in ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA are up to date. Will not download again.
17:39:36.916 DEBUG  Copying files from . into ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA
17:39:37.199 DEBUG  Setting working directory to ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA
17:39:37.199 DEBUG  The file path ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA/provider.tf already exists, but was a previously generated file by terragrunt. Since if_exists for code generation is set to "overwrite_terragrunt", regenerating file.
17:39:37.202 DEBUG  Generated file ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA/provider.tf.
17:39:37.239 DEBUG  Running command: terraform console
17:39:37.239 DEBUG  Engine is not enabled, running command directly in ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA
17:39:37.240 ERROR  Error closing pty: invalid argument
17:39:37.240 ERROR  terraform invocation failed in ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA
17:39:37.241 ERROR  error occurred:

* Failed to execute "terraform console" in ./.terragrunt-cache/RNJ0idZ78sgcGuo079PsS-TYfWQ/ThyYwttwki6d6AS3aD5OwoyqIWA

  fork/exec /usr/bin/terraform: operation not permitted

17:39:37.241 DEBUG  *fs.PathError fork/exec /usr/bin/terraform: operation not permitted
/home/circleci/project/internal/os/exec/ptty_unix.go:40 (0x1510f2c)
/home/circleci/project/internal/os/exec/cmd.go:61 (0x1510387)
/home/circleci/project/shell/run_shell_cmd.go:193 (0x16a9715)
/home/circleci/project/telemetry/metrics.go:42 (0xaaf473)
/home/circleci/project/telemetry/telemetry.go:80 (0x16a80cd)
/home/circleci/project/telemetry/traces.go:38 (0xab1e0f)
/home/circleci/project/telemetry/telemetry.go:79 (0x16a7fc9)
/home/circleci/project/shell/run_shell_cmd.go:111 (0x16a7c4b)
/home/circleci/project/shell/run_shell_cmd.go:72 (0x16a7b05)
/home/circleci/project/cli/commands/terraform/action.go:457 (0x1bc73c9)
/home/circleci/project/cli/commands/terraform/action.go:327 (0x1bc66dc)
/home/circleci/project/cli/commands/terraform/action.go:419 (0x1bc6f0c)
/home/circleci/project/cli/commands/terraform/action.go:326 (0x1bc62ce)
/home/circleci/project/cli/commands/terraform/action.go:237 (0x1bc58c7)
/home/circleci/project/cli/commands/terraform/action.go:83 (0x1bc4b32)
/home/circleci/project/cli/commands/terraform/command.go:47 (0x22cf505)
/home/circleci/project/cli/app.go:235 (0x22d0f47)
/home/circleci/go/pkg/mod/golang.org/x/sync@v0.8.0/errgroup/errgroup.go:78 (0x165d5d0)
/usr/local/go/src/runtime/asm_amd64.s:1700 (0x477c21)

17:39:37.241 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1

Versions

denis256 commented 3 weeks ago

It looks like you might be encountering a permissions issue when Terragrunt is trying to execute the terraform binary at /usr/bin/terraform. To help diagnose this further, I'd recommend checking the following:

  1. Confirm that /usr/bin/terraform is a valid script and executable: Run the following commands to check if the binary exists and has executable permissions:

    ls -la /usr/bin/terraform

    Ensure the output indicates that the file exists and has execute (x) permissions. If not, you can add execute permissions like so:

    chmod +x /usr/bin/terraform
  2. Verify that terraform runs without Terragrunt: Test whether the terraform binary runs independently by running:

    /usr/bin/terraform --version

    If this command works, it suggests that terraform itself is correctly set up.

  3. Provide steps to reproduce: If the binary is valid and executable but the issue persists, it would help to share an example repository and detailed steps on how to reproduce the issue.

denis256 commented 3 weeks ago

Hm, it happens on my env too :thinking:

 terragrunt console --terragrunt-log-level debug
[INFO] Getting version from tgenv-version-name
[INFO] TGENV_VERSION is 0.68.4
17:05:25.495 DEBUG  Terragrunt Version: 0.68.4
17:05:25.496 DEBUG  Did not find any locals block: skipping evaluation.
17:05:25.496 DEBUG  Running command: tofu --version
17:05:25.496 DEBUG  Engine is not enabled, running command directly in .
17:05:25.533 DEBUG  tofu version: 1.7.0
17:05:25.533 DEBUG  Reading Terragrunt config file at ./terragrunt.hcl
17:05:25.533 DEBUG  Did not find any locals block: skipping evaluation.
17:05:25.534 DEBUG  Did not find any locals block: skipping evaluation.
17:05:25.536 DEBUG  Running command: tofu init
17:05:25.537 DEBUG  Engine is not enabled, running command directly in .
17:05:25.567 STDOUT tofu: Initializing the backend...
17:05:25.567 STDOUT tofu: Initializing provider plugins...
17:05:25.567 STDOUT tofu: OpenTofu has been successfully initialized!
17:05:25.567 STDOUT tofu: 
17:05:25.567 STDOUT tofu: You may now begin working with OpenTofu. Try running "tofu plan" to see
17:05:25.567 STDOUT tofu: any changes that are required for your infrastructure. All OpenTofu commands
17:05:25.567 STDOUT tofu: should now work.
17:05:25.567 STDOUT tofu: If you ever set or change modules or backend configuration for OpenTofu,
17:05:25.567 STDOUT tofu: rerun this command to reinitialize your working directory. If you forget, other
17:05:25.567 STDOUT tofu: commands will detect it and remind you to do so if necessary.
17:05:25.571 DEBUG  Running command: tofu console
17:05:25.571 DEBUG  Engine is not enabled, running command directly in .
17:05:25.571 ERROR  Error closing pty: invalid argument
17:05:25.572 ERROR  tofu invocation failed in .
17:05:25.572 ERROR  error occurred:

* Failed to execute "tofu console" in .

  fork/exec /home/denis256/bin/tofu: operation not permitted

17:05:25.572 DEBUG  *fs.PathError fork/exec /home/denis256/bin/tofu: operation not permitted
/home/circleci/project/internal/os/exec/ptty_unix.go:40 (0x1510f2c)
/home/circleci/project/internal/os/exec/cmd.go:61 (0x1510387)
/home/circleci/project/shell/run_shell_cmd.go:193 (0x16a9715)
/home/circleci/project/telemetry/metrics.go:42 (0xaaf473)
/home/circleci/project/telemetry/telemetry.go:80 (0x16a80cd)
/home/circleci/project/telemetry/traces.go:38 (0xab1e0f)
/home/circleci/project/telemetry/telemetry.go:79 (0x16a7fc9)
/home/circleci/project/shell/run_shell_cmd.go:111 (0x16a7c4b)
/home/circleci/project/shell/run_shell_cmd.go:72 (0x16a7b05)
/home/circleci/project/cli/commands/terraform/action.go:457 (0x1bc73c9)
/home/circleci/project/cli/commands/terraform/action.go:327 (0x1bc66dc)
/home/circleci/project/cli/commands/terraform/action.go:419 (0x1bc6f0c)
/home/circleci/project/cli/commands/terraform/action.go:326 (0x1bc62ce)
/home/circleci/project/cli/commands/terraform/action.go:237 (0x1bc58c7)
/home/circleci/project/cli/commands/terraform/action.go:83 (0x1bc4b32)
/home/circleci/project/cli/commands/terraform/command.go:47 (0x22cf505)
/home/circleci/project/cli/app.go:235 (0x22d0f47)
/home/circleci/go/pkg/mod/golang.org/x/sync@v0.8.0/errgroup/errgroup.go:78 (0x165d5d0)
/usr/local/go/src/runtime/asm_amd64.s:1700 (0x477c21)

17:05:25.572 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1
nvigot commented 3 weeks ago

There is a regression between versions v0.68.0-beta2024100702 and terragrunt-v0.68.0-beta2024100801, confirmed on Linux and RHEL with both OpenTofu and Terraform. The other functionalities remain unaffected.

$ terragrunt-v0.68.0-beta2024100702 --version
terragrunt version v0.68.0-beta2024100702

$ terragrunt-v0.68.0-beta2024100702 console
19:30:13.129 INFO   Retrieved output from terraform
>
$ terragrunt-v0.68.0-beta2024100801 --version
terragrunt version v0.68.0-beta2024100801

$ terragrunt-v0.68.0-beta2024100801 console
19:30:57.923 ERROR  Error closing pty: invalid argument
19:30:57.926 ERROR  terraform invocation failed in .
19:30:57.926 ERROR  error occurred:

* Failed to execute "terraform console" in .

  fork/exec /opt/homebrew/bin/terraform: operation not permitted

19:30:57.927 ERROR  Unable to determine underlying exit code, so Terragrunt will exit with error code 1
micolun commented 3 weeks ago

Can report, happens the same for me. Terragrunt unable to run terraform console terragrunt: 0.68.4 terraform: 1.7.5

levkohimins commented 2 weeks ago

Resolved in v0.68.5 release.