8

I am trying to Provision VMs on KVM with Terraform. one of the steps in installations is to download and install the provider buy the command:

go install github.com/dmacvicar/terraform-provider-libvirt@latest

but it errors:

The go.mod file for the module providing named packages contains one or more replace directives. It must not contain directives that would cause it to be interpreted differently than if it were the main module.

I didn't find a solution, is someone has faced it? thank you

Orly Orly
  • 367
  • 5
  • 16

1 Answers1

11

As JimB notice in comments:

If there are replace or exclude directives in the module, the correct installation method is to clone the source and install it,

git clone github.com/dmacvicar/terraform-provider-libvirt
cd terraform-provider-libvirt
go install
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
  • 2
    `go get` is deprecated as an installation command, and is only for managing dependencies. `go install` is the correct command once the correct source has been checked out locally to that replace directives can be used. – JimB Nov 02 '21 at 11:36
  • Thanks, I've updated answer. – Roman Kiselenko Nov 02 '21 at 13:47
  • No, you shouldn't rely on trying to use `go install` then having it fail and changing into the `GOPATH/pkg/mod` source directory (if `go install worked, then there would be nothing else to do) - you checkout the desired source and build that source. – JimB Nov 02 '21 at 14:04
  • I've checked it and go install wont compile anything. – Roman Kiselenko Nov 02 '21 at 14:10
  • it just clone sources in the `GOPATH/pkg/mod` – Roman Kiselenko Nov 02 '21 at 14:11
  • That is true, but you're relying on `go install` erroring out here with the error above, and `GOPATH/pkg/mod` is not intended for direct usage (which is why it's all created read-only). If there are `replace` or `exclude` directives in the module, the correct installation method is to clone the source and `install` it, there's no reason to recommend otherwise. – JimB Nov 02 '21 at 14:23
  • Ok, thanks, now it's clear for me, I've updated answer. – Roman Kiselenko Nov 02 '21 at 14:26