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 = "[email protected]: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

1 Answer 1

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.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .