0

What command line option and environment variables control how terraform finds keys for downloading modules from git?

When using terraform modules from a git repo I'm running into problems when I execute the plan via jenkins build server.

I'm using modules with a source like this:

source = "git@github.com:mygroup/myrepo.git//mymodule"

Which results in the following as the private / deploy key isn't in the jenkins user's home/.ssh dir

Permission denied (publickey).
fatal: Could not read from remote repository.

I can use a WithEnv(["HOME=dir"]) clause and build up a .ssh directory but I think there must be a more elegant withCredential + command line option to handle this scenario.

Do you know of a better approach?

Thanks

Eva Brigid
  • 75
  • 7

1 Answers1

0

Wrap your terraform steps in sshagent:

sshagent(['my-credential-id']) {
  sh 'terraform init'
  // etc.
}

Replace my-credential-id with the ID of the credential containing your deploy private key.

jayhendren
  • 1,014
  • 5
  • 12
  • Oh that's awesome. I wish I'd found that prior to implementing my own. Silly me. Thanks Jay. https://serverfault.com/questions/927712/git-clone-hangs-during-clone-when-using-sshpass – Eva Brigid Aug 24 '18 at 14:27