如何在CircleCI Go图像中使用地形

如何在CircleCI Go图像中使用地形,go,terraform,circleci,terratest,Go,Terraform,Circleci,Terratest,我已经为我的Terraform代码准备了基于Go的自动化测试,我希望它们能在CircleCI中运行。为此,我为CircleCI提供了以下config.yml: version: 2 jobs: build: docker: - image: circleci/golang:1.12 - image: hashicorp/terraform:light working_directory: /go/src/bitbucket.org/teapigst

我已经为我的Terraform代码准备了基于Go的自动化测试,我希望它们能在CircleCI中运行。为此,我为CircleCI提供了以下config.yml:

version: 2

jobs:
  build:
    docker:
      - image: circleci/golang:1.12
      - image: hashicorp/terraform:light

    working_directory: /go/src/bitbucket.org/teapigsteam/findmytea-terraform
    steps:
      - checkout

      - run: go get -v -t -d ./...
      - run: go test -v ./...
但由于某些原因,Go无法找到Terraform可执行文件:

#!/bin/bash -eo pipefail
go test -v ./...
=== RUN   TestFindMyTeaApp
TestFindMyTeaApp 2020-03-21T12:20:26Z retry.go:72: terraform [init -upgrade=false]
TestFindMyTeaApp 2020-03-21T12:20:26Z command.go:87: Running command terraform with args [init -upgrade=false]
TestFindMyTeaApp 2020-03-21T12:20:26Z retry.go:80: Returning due to fatal error: FatalError{Underlying: exec: "terraform": executable file not found in $PATH}
TestFindMyTeaApp 2020-03-21T12:20:26Z retry.go:72: terraform [destroy -auto-approve -input=false -var app_name=findmytea-terraform-tdd -lock=false]
TestFindMyTeaApp 2020-03-21T12:20:26Z command.go:87: Running command terraform with args [destroy -auto-approve -input=false -var app_name=findmytea-terraform-tdd -lock=false]
TestFindMyTeaApp 2020-03-21T12:20:26Z retry.go:80: Returning due to fatal error: FatalError{Underlying: exec: "terraform": executable file not found in $PATH}
--- FAIL: TestFindMyTeaApp (0.00s)
    apply.go:13: 
            Error Trace:    apply.go:13
                                        findmyteaui_test.go:19
            Error:          Received unexpected error:
                            FatalError{Underlying: exec: "terraform": executable file not found in $PATH}
            Test:           TestFindMyTeaApp
    destroy.go:11: 
            Error Trace:    destroy.go:11
                                        panic.go:406
                                        testing.go:609
                                        apply.go:13
                                        findmyteaui_test.go:19
            Error:          Received unexpected error:
                            FatalError{Underlying: exec: "terraform": executable file not found in $PATH}
            Test:           TestFindMyTeaApp
FAIL
FAIL    bitbucket.org/teapigsteam/findmytea-terraform/test  0.005s

Exited with code exit status 1
CircleCI received exit code 1

谁能告诉我我做错了什么?或者这是不可能的?

与其尝试使用两个Docker图像,不如尝试使用hashicorp/terraform:full

我相信您看到这个错误是因为您的代码在Golang容器中执行,而Golang容器无法访问Terraform light容器中的可执行文件


您可以创建一个自定义Docker映像来运行它,并手动安装Terraform。然而,
hashicorp/terraform:full
图像无论如何都是建立在Golang图像之上的,因此理论上应该会让你更接近你的目标。

与其尝试使用两个Docker图像,不如尝试只使用
hashicorp/terraform:full

我相信您看到这个错误是因为您的代码在Golang容器中执行,而Golang容器无法访问Terraform light容器中的可执行文件


您可以创建一个自定义Docker映像来运行它,并手动安装Terraform。然而,hashicorp/terraform:full图像是建立在Golang图像之上的,因此理论上应该会让你更接近你的目标。

就是这样!通过添加add--no cache gcc musl dev,您可能可以通过设置
CGO_ENABLED=0
放弃这些功能!通过添加add--no cache gcc musl dev,您可以通过设置
CGO_ENABLED=0