Error trying to import nomad go module

Probably a question that’s a bit out of the ordinary.

I have the use case where I have to parse nomad job files from a go program. There are some 3rd party libs that do this, however, I’m trying to use nomad’s own implementation to do so via:

https://pkg.go.dev/github.com/hashicorp/nomad/jobspec2

However, when trying to get the modules with go get github.com/hashicorp/nomad/jobspec2 I get the following errors:

# github.com/hashicorp/nomad/jobspec2
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:293:16: tg.Scaling.Type undefined (type *api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:294:14: tg.Scaling.Type undefined (type *api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:443:7: p.Type undefined (type api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:444:5: p.Type undefined (type api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:445:14: p.Type undefined (type api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:451:7: p.Type undefined (type api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:457:37: task.ScalingPolicies undefined (type *api.Task has no field or method ScalingPolicies)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:465:11: invalid operation: p.Max != nil (mismatched types int64 and nil)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:465:22: p.Type undefined (type *api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:485:6: p.Type undefined (type *api.ScalingPolicy has no field or method Type)
../../../../go/pkg/mod/github.com/hashicorp/nomad@v1.2.4/jobspec2/hcl_conversions.go:485:6: too many errors

I looked at the files and it seems that these are not actually defined. I’m still a bit of a go noob so I’m not sure what I’m doing wrong.

Hi @jcrsilva. Thanks for using Nomad!

If you look at the jobspec2 directory you will notice that there is no go.mod file in that directory. This means that the jobspec2 package is not a standalone package, but rather part of the nomad package.

If you run go get github.com/hashicorp/nomad , you should then be able to add this to your go file to use jobspec2.

import (
    "github.com/hashicorp/nomad/jobspec2"
)

Hey Derek, I tried doing that and I got exactly the same errors, I’m guessing this has to do with some inconsistencies between the modules that are in master on that repo; but this is pure speculation on my part as I’m not aware of how go actually pulls in module dependencies.

However, I looked at levant and copied the module versions that the repo uses and everything worked just fine!

hi @jcrsilva

Thanks for the follow up. I went and tested this this morning (which I should have done before sorry!) and I had the same experience! Thank you for being persistent! Would you mind logging an issue in the Nomad repo for this? It would be great to have a community member report the issue and I will confirm that I can reproduce. If you don’t have time, I understand, but we’d like to make sure you are involved in the process, and receive updates as the issue progresses through resolution.

Hey Derek,

Apologies for the time in responding to this. The levant workaround worked just fine, so although unwieldy I forgot about the subject. Will create an issue.