Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terraform init fails - git must be available and on the PATH

Tags:

git

terraform

I'm facing a problem when running terraform init / get.

Error I'm getting:

Error downloading modules: Error loading modules: error downloading 'ssh://[email protected]/etc etc': git must be available and on the PATH

The github path is correct, works fine on another machine.

Git works fine, it's in the PATH as well. TF_LOGs are empty. Working on ubuntu.

Thanks!

like image 433
metgale Avatar asked Jan 28 '19 16:01

metgale


3 Answers

I don't know if you solved your issue or not but I ran into the same problem and then solved it. Sharing the answer in case someone else needs help.

For reference I encountered this issue on

  • Ubuntu 18.04
  • Linux Ubuntu 4.15.0-45-generic
  • Terraform v0.11.11 Rev 216 installed via Snap

The error comes from the file terraform/vendor/github.com/hashicorp/go-getter/get_git.go the Get function. The first thing that is attempted by the function is the following call

if _, err := exec.LookPath("git"); err != nil {
   return fmt.Errorf("git must be available and on the PATH")
}

This causes go to search all of the folders listed in path for a file with the supplied name, in this case git. I created and executed a go script that makes the same call and it behaved as expected, finding git without error.

After this I uninstalled terraform from snap and downloaded the executable straight from the Hashicorp website. When I ran that version of the executable which was still v0.11.11 it ran without issue. This leads me to believe that the error has something to do with how snap was running the executable or the permission model around snap installed apps.

TL;DR: Uninstall the snap installed version of Terraform and instead download and use the Hashicorp binary.

like image 123
hpoe Avatar answered Nov 02 '22 21:11

hpoe


Uninstall the snap installed version of Terraform and instead download and use the Hashicorp binary.

like image 27
Ruslan Bondarau Avatar answered Nov 02 '22 21:11

Ruslan Bondarau


As per the terraform documentation,

For github.com projects, to clone over SSH, use the
following form:

module "consul" {
  source = "[email protected]:hashicorp/example.git"
}

For Arbitrary Git repositories use the special git:: prefix

module "storage" {
  source = "git::ssh://[email protected]/storage.git"
}

Also, verify if Config ~/.ssh/config is correct for your github account:

Hope this helps.

like image 41
R.S Avatar answered Nov 02 '22 22:11

R.S