【问题标题】:Terratest does not find terraform on MacTerratest 在 Mac 上找不到 terraform
【发布时间】:2020-07-02 13:47:31
【问题描述】:

我正在尝试编写一个简单的go测试如下


import (
    "testing"

    "github.com/gruntwork-io/terratest/modules/terraform"
    "github.com/stretchr/testify/assert"
)

func TestCoreInfoOutput(t *testing.T) {
    terraformOptions := &terraform.Options{
        TerraformDir: "../examples/output.tf",
    }

    defer terraform.Destroy(t, terraformOptions)

    terraform.InitAndApply(t, terraformOptions)

    output := terraform.Output(t, terraformOptions, "test_name_prefix")
    assert.Equal(t, "dev-use1-hello_world-", output)
}

但是当我运行go test my_test.go 时,我收到以下错误

    apply.go:13: 
            Error Trace:    apply.go:13
                                        my_test.go:17
            Error:          Received unexpected error:
                            FatalError{Underlying: fork/exec /usr/local/bin/terraform: not a directory}
            Test:           TestCoreInfoOutput
    destroy.go:11: 
            Error Trace:    destroy.go:11
                                        panic.go:615
                                        testing.go:657
                                        apply.go:13
                                        core-info_test.go:17
            Error:          Received unexpected error:
                            FatalError{Underlying: fork/exec /usr/local/bin/terraform: not a directory}
            Test:           my_Test
FAIL

这是文件夹结构

--module 
    --core-info
      --examples
        --core-info.tf
        --output.tf
      --test
         my_test.go

我基本上想在我的测试中测试 output.tf 中的输出值。

编辑:

在我将文件更改为文件的目录后,它失败并出现以下错误

goroutine 23 [IO wait]:
internal/poll.runtime_pollWait(0x9804f28, 0x72, 0xffffffffffffffff)
    /usr/local/go/src/runtime/netpoll.go:203 +0x55
internal/poll.(*pollDesc).wait(0xc00011c7f8, 0x72, 0x1001, 0x1000, 0xffffffffffffffff)
    /usr/local/go/src/internal/poll/fd_poll_runtime.go:87 +0x45
internal/poll.(*pollDesc).waitRead(...)
    /usr/local/go/src/internal/poll/fd_poll_runtime.go:92
internal/poll.(*FD).Read(0xc00011c7e0, 0xc0001a6000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
    /usr/local/go/src/internal/poll/fd_unix.go:169 +0x201
os.(*File).read(...)
    /usr/local/go/src/os/file_unix.go:263
os.(*File).Read(0xc00011a080, 0xc0001a6000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
    /usr/local/go/src/os/file.go:116 +0x71
bufio.(*Scanner).Scan(0xc000180300, 0x0)
    /usr/local/go/src/bufio/scan.go:213 +0xa4
github.com/gruntwork-io/terratest/modules/shell.readData(0x13ebf20, 0xc00014a7e0, 0xc000180300, 0xc00011ebc0, 0xc00011eb88, 0xc00012d020)
    /Users/me/go/src/github.com/gruntwork-io/terratest/modules/shell/command.go:151 +0xc9
created by github.com/gruntwork-io/terratest/modules/shell.readStdoutAndStderr
    /Users/me/go/src/github.com/gruntwork-io/terratest/modules/shell/command.go:135 +0x257
FAIL    command-line-arguments  600.060s
FAIL

【问题讨论】:

    标签: macos terraform terratest


    【解决方案1】:

    TerraformDir option 应设置为文件夹路径而不是文件路径。

        TerraformDir: "../examples",
    

    "../examples/output.tf" 不是文件夹路径

    【讨论】:

    • 太棒了!!!!这使得测试执行,但我在示例文件夹下有两个 .tf 文件,测试似乎卡在这一行----`运行命令 terraform with args [apply -input=false -auto-approve -lock=false ]`
    • 编辑您的问题以包含 .tf 文件。另外,系统PATH 中有 terraform 二进制文件吗?
    • 是的,它在我的路径中,我编辑了我的问题,也出现了失败的错误
    • 你的 terraform 版本是什么,你的 .tf 文件是用什么语法版本编写的?
    • 我的 terraform 版本是 v0.12.24,我能够对 .tf 文件进行 terraform 应用,它只是失败得如此可怕的 terratest
    猜你喜欢
    • 2011-11-09
    • 2013-06-12
    • 2015-05-19
    • 2021-02-19
    • 2016-07-19
    • 2017-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多