Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modules/terraform/var-file.go:142:8: undefined: hcl.Decode #784

Closed
WafflesMcDuff opened this issue Feb 15, 2021 · 16 comments · Fixed by #790
Closed

modules/terraform/var-file.go:142:8: undefined: hcl.Decode #784

WafflesMcDuff opened this issue Feb 15, 2021 · 16 comments · Fixed by #790
Labels
bug Something isn't working

Comments

@WafflesMcDuff
Copy link

WafflesMcDuff commented Feb 15, 2021

Latest release is causing an error:

vendor/github.com/gruntwork-io/terratest/modules/terraform/var-file.go:142:8: undefined: hcl.Decode
FAIL	git.*******.com/mongodbatlas-tf/terratest/mongodbatlas-cluster [build failed]
FAIL

Exited with code exit status 2

err = hcl.Decode(out, string(fileContents))

@WafflesMcDuff
Copy link
Author

@brikis98
@alpacamybags118

@WafflesMcDuff
Copy link
Author

Problem started with #733

@WafflesMcDuff
Copy link
Author

Apparently this version breaks compatibility with go dep.
Had to switch from
dep init && dep ensure -vendor-only
to
go mod init git.rockfin.com/mongodbtatlas-tf && go mod vendor

@alpacamybags118
Copy link
Contributor

I think the root of the issue is dep is trying to pull v2 of hcl while the go mod of the terratest library explicitly referenes v1, so dep isnt respecting the libraries required version

@bgarcial
Copy link

bgarcial commented Feb 16, 2021

@alpacamybags118, @WafflesMcDuff I got the same error when running go get -u github.com/gruntwork-io/terratest/modules/terraform in a pipeline.

> go get -u github.com/gruntwork-io/terratest/modules/terraform
# github.com/gruntwork-io/terratest/modules/terraform
../../go/src/github.com/gruntwork-io/terratest/modules/terraform/var-file.go:142:8: undefined: hcl.Decode

Meanwhile, I just remove the generic latest dependency called from the YAML file of my pipeline by executing go get command (go get -u github.com/gruntwork-io/terratest/modules/terraform which one is calling the v0.32.6 release), and I am just using the version from go.mod file of my test directory of this way:

> go mod init my-project/tests
go: creating new go.mod: module fem-downloader/tests
  • This makes go.mod call the v0.32.7 of terratest package, which one is the last version.
module my-project/tests

go 1.15

require (
	github.com/gruntwork-io/terratest v0.32.7
	github.com/stretchr/testify v1.7.0
)

And by default the GitHub actions pipeline is taking it:

.
.
go: downloading github.com/gruntwork-io/terratest v0.32.7
.
go: downloading github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
go: downloading github.com/hashicorp/go-multierror v1.1.0
go: downloading github.com/hashicorp/errwrap v1.0.0
.
.

@avishnyakov
Copy link

Confirming, having same problem with the recent changes. Testing, trying to find a workaround.

@getSurreal
Copy link

As WafflesMcDuff mentioned, use

go mod init

instead of

dep init

@yorinasub17 yorinasub17 added question bug Something isn't working and removed question labels Feb 18, 2021
@yorinasub17
Copy link
Contributor

This is indeed a bug as we should be using hclv2. Will work on updating the library function to use hcl v2 asap.

@jnovick
Copy link

jnovick commented Feb 23, 2021

This issue is affecting me as well. Part of the pipeline we wrote ensures we always use the latest terratest version so it has been broken and preventing any tests from actually running.

@yorinasub17
Copy link
Contributor

Potential fix for this was released https://github.com/gruntwork-io/terratest/releases/tag/v0.32.8

Please try it out and see if it resolves this.

@yorinasub17 yorinasub17 reopened this Feb 23, 2021
@jnovick
Copy link

jnovick commented Feb 23, 2021

Unfortunately I am still having this issue. I assume that is why you re-opened the issue, but wanted to comment in case you were unaware.

@yorinasub17
Copy link
Contributor

yorinasub17 commented Feb 23, 2021

Can you share with me the error message you got? It should be different since the call to hcl.Decode is no longer in the source code.

If you are still getting the same error message, then you need to first bump terratest in your go.mod and in your vendored folder (if you are using vendoring).

@jnovick
Copy link

jnovick commented Feb 24, 2021

It is different now. Is this a separate issue or still the same issue?

package command-line-arguments (test)
	imports github.com/gruntwork-io/terratest/modules/terraform
	imports github.com/hashicorp/hcl/v2/hclparse: cannot find package "github.com/hashicorp/hcl/v2/hclparse" in any of:
	/usr/vsts/pipeline-agent1/_work/_tool/go/1.13.5/x64/src/github.com/hashicorp/hcl/v2/hclparse (from $GOROOT)
	/home/Azureuser/go/src/github.com/hashicorp/hcl/v2/hclparse (from $GOPATH)

@yorinasub17
Copy link
Contributor

Ah yes this is a separate issue. Can you try running go mod tidy to see if that resolves your issue?

@jnovick
Copy link

jnovick commented Feb 26, 2021

I was able to fix my new issue with GO111MODULE=on as per hashicorp/hcl#371 so your update to terratest resolved my problems. Thank you.

@yorinasub17
Copy link
Contributor

Thanks for confirming! Will close this issue then. Please open a new issue if you run into other issues with go dependencies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants