apparentlymart / terraform-clean-syntax

A simple tool for Terraform language syntax cleanup, extending terraform fmt
Mozilla Public License 2.0
160 stars 24 forks source link

cannot find package "github.com/hashicorp/hcl/v2/hclsyntax" #8

Closed queglay closed 4 years ago

queglay commented 4 years ago

Thanks for working on this tool! I already upgraded to .12 but it seems now that your script would be a prerequisite to fix things in .12.18 such as -

Warning: Interpolation-only expressions are deprecated
  on modules/deadline/main.tf line 115, in resource "aws_iam_instance_profile" "spot_instance_profile":
 115:   name = "${aws_iam_role.spot_instance_role.name}"

when I attempt to get this package though I get errors in ubuntu. I've never used go before though, so sorry if I've missed something!

vagrant@openfirehawkserverdev:~$ go get github.com/apparentlymart/terraform-clean-syntax
package github.com/hashicorp/hcl/v2: cannot find package "github.com/hashicorp/hcl/v2" in any of:
    /usr/local/go/src/github.com/hashicorp/hcl/v2 (from $GOROOT)
    /home/vagrant/go/src/github.com/hashicorp/hcl/v2 (from $GOPATH)
package github.com/hashicorp/hcl/v2/hclsyntax: cannot find package "github.com/hashicorp/hcl/v2/hclsyntax" in any of:
    /usr/local/go/src/github.com/hashicorp/hcl/v2/hclsyntax (from $GOROOT)
    /home/vagrant/go/src/github.com/hashicorp/hcl/v2/hclsyntax (from $GOPATH)
package github.com/hashicorp/hcl/v2/hclwrite: cannot find package "github.com/hashicorp/hcl/v2/hclwrite" in any of:
    /usr/local/go/src/github.com/hashicorp/hcl/v2/hclwrite (from $GOROOT)
    /home/vagrant/go/src/github.com/hashicorp/hcl/v2/hclwrite (from $GOPATH)

vagrant@openfirehawkserverdev:~$ go get github.com/hashicorp/hcl/v2
package github.com/hashicorp/hcl/v2: cannot find package "github.com/hashicorp/hcl/v2" in any of:
    /usr/local/go/src/github.com/hashicorp/hcl/v2 (from $GOROOT)
    /home/vagrant/go/src/github.com/hashicorp/hcl/v2 (from $GOPATH)
apparentlymart commented 4 years ago

Hi @queglay! It looks like your vagrant development environment is set up in "GOPATH mode", which is the older development model prior to the introduction of Go Modules. The pre-modules mode does not support there being multiple selectable versions of a module, so it only knows how to select the v1 release of HCL, and cannot install the v2 release which this tool (and Terraform) uses.

You can build this tool in modules mode as follows:

mars commented 4 years ago

I started out seeing the same "cannot find package" error.

Following your steps @apparentlymart , I end-up with this error instead:

$ go install
go: finding github.com/hashicorp/hcl/v2 v2.1.1-0.20191206020329-84e71e9393a0
go: github.com/hashicorp/hcl/v2@v2.1.1-0.20191206020329-84e71e9393a0: unknown revision 84e71e9393a0
go: error loading module requirements

So, not able to try out this nifty tool.

apparentlymart commented 4 years ago

Hmm I had switched the version of hcl/v2 here to point at a specific commit in order to get an upstream HCL fix that wasn't merged yet, but it seems like now that the fix is merged that commit doesn't lead anywhere anymore.

Since that fix has now been included in a release I'll flip this codebase over to depend on HCL's v2.2.0 release tag rather than this commit 84e71e9393a0.

mars commented 4 years ago

Pulled master with your fix. It now installs & runs successfully ✅

Thank you @apparentlymart 😄

queglay commented 4 years ago

Maneged to get it working, thankyou for providing this @apparentlymart !