gruntwork-io / terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
https://terratest.gruntwork.io/
Apache License 2.0
7.47k stars 1.32k forks source link

Cannot run tests from Github Actions - ""tofu": executable file not found in $PATH; } " #1388

Open mrybson opened 8 months ago

mrybson commented 8 months ago

Describe the bug I am trying to run the terratests from Github Actions. It works fine locally, but I am getting below error when running from the GH Runner.

To Reproduce

name: Integration Tests
on:
  workflow_dispatch
jobs:
  go-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version: '1.21'

      - name: Create module
        working-directory: terraform/tests
        run: go mod init "mymod"  

      - name: Go mod tidy
        working-directory: terraform/tests
        run: go mod tidy

      - name: Run Tests
        working-directory: terraform/tests
        run: go test -v -tags mytag

Expected behavior Tests are getting executed.

Terminal output

[Integration Tests/go-tests] ⭐ Run Main Run Tests [Integration Tests/go-tests] 🐳 docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/4] user= workdir=terraform/tests | === RUN MyTestFunction1 | === PAUSE MyTestFunction1 | === CONT MyTestFunction1 | myTest.go:31: mLaAA7 | MyTestFunction1 2024-01-25T16:54:12Z retry.go:91: tofu [init -upgrade=false] | MyTestFunction1 2024-01-25T16:54:12Z logger.go:66: Running command tofu with args [init -upgrade=false] | MyTestFunction1 2024-01-25T16:54:12Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exec: "tofu": executable file not found in $PATH; } | apply.go:15: | Error Trace: /root/go/pkg/mod/github.com/gruntwork-io/terratest@v0.46.11/modules/terraform/apply.go:15 | /mnt/c/repos/terraform-templates-deployment/terraform/tests/myTest.go:48 | Error: Received unexpected error: | FatalError{Underlying: error while running command: exec: "tofu": executable file not found in $PATH; } | Test: MyTestFunction1 | MyTestFunction1 2024-01-25T16:54:12Z retry.go:91: tofu [destroy -auto-approve -input=false -var postfix=mlaaa7 -lock=false] | MyTestFunction1 2024-01-25T16:54:12Z logger.go:66: Running command tofu with args [destroy -auto-approve -input=false -var postfix=mlaaa7 -lock=false] | MyTestFunction1 2024-01-25T16:54:12Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exec: "tofu": executable file not found in $PATH; } | destroy.go:11: | Error Trace: /root/go/pkg/mod/github.com/gruntwork-io/terratest@v0.46.11/modules/terraform/destroy.go:11 | /opt/hostedtoolcache/go/1.21.6/x64/src/runtime/panic.go:523 | /opt/hostedtoolcache/go/1.21.6/x64/src/testing/testing.go:999 | /root/go/pkg/mod/github.com/gruntwork-io/terratest@v0.46.11/modules/terraform/apply.go:15 | /mnt/c/repos/terraform-templates-deployment/terraform/tests/myTest.go:48 | Error: Received unexpected error: | FatalError{Underlying: error while running command: exec: "tofu": executable file not found in $PATH; } | Test: MyTestFunction1 | --- FAIL: MyTestFunction1 (0.00s) | FAIL | exit status 1

Versions

Additional I don't want to use tofu. I want to use terraform. I tried installing terraform as part of the Github action workflow, but that does not make any difference.

msl0 commented 1 month ago

I had a similar problem locally. The same error occurred when the terraform command was not available in the terminal. Make sure that Terraform is installed and the path to the directory where the Terraform executable exists is in the PATH environment variable. Try running the terraform --version command via the workflow to verify it

Check this out for more information

1333

https://github.com/gruntwork-io/terratest/releases/tag/v0.46.0