gpt4 book ai didi

go - 如何在CircleCI Go图像中使用Terraform

转载 作者:行者123 更新时间:2023-12-01 22:07:14 27 4
gpt4 key购买 nike

我已经为我的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容器中执行,而该容器无法访问Terraform light容器中的可执行文件。

您可能已经创建了一个自定义Docker镜像来运行该镜像,并手动安装了Terraform。但是,无论如何,hashicorp/terraform:full图像都是建立在Golang图像之上的,因此理论上应该使您更接近目标。

关于go - 如何在CircleCI Go图像中使用Terraform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60787758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com