I've got Go based automated tests for my Terraform code and I'd like to get them to run in CircleCI. To this end I have the following config.yml for CircleCI:
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 ./...
But for some reason, Go cannot find the Terraform executable:
#!/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
Can anyone tell me what I'm doing wrong? Or maybe this just isn't possible?
Instead of trying to use two Docker images, try to just use hashicorp/terraform:full
?
I believe you are seeing this error because your code is executing within the Golang container, which has no access to the executables within the Terraform light container.
You could have created a custom Docker image to run this in, and installed Terraform manually. However, the hashicorp/terraform:full
image is built on top of the Golang image anyway, so should theoretically bring you closer to your goal.