go - 如何在 CircleCI Go 图像中使用 Terraform
问题描述
我已经为我的 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 轻容器中的可执行文件。
您可以创建一个自定义 Docker 映像来运行它,并手动安装 Terraform。但是,hashicorp/terraform:full
无论如何,该图像都是建立在 Golang 图像之上的,因此理论上应该让您更接近您的目标。
推荐阅读
- javascript - Uncaught Promise Rejection SyntaxError: 位置 0 处 JSON 中的意外标记 u
- javascript - 如何在 node.js 中获取 firebase 实时数据库的子节点值?
- r - 有没有办法从 csv 文件中组合多个时间序列,以便值匹配日期
- sql - 如何将另一个表中的字段添加到左连接查询 MS Access
- python - python报纸3k按字符串返回article_html,我想删除匹配的字符串
- c# - 如何在标签名称中设置变量
- recursion - 如何将具有两次调用自身的递归函数转换为迭代?
- python - 当一个不存在时,如何在 Jinja 中对多个属性进行排序?
- java - 无法配置 EMDK 版本 7.4.0
- powershell - Powershell 小于 "-lt" 评估为假,即使它仅在某些数字上为真