Jenkinsfile and terraform modules in github: how to authenticate by key?

I have:

  • main github repo with Terraform12 code
  • module in secondary repo which is referred as source = ""
  • Jenkins 2.249 (can’t update now)
  • a private ssh key in Jenkins to access mod_repo

When I try to run terraform init in Jenkins pipeline I get

Could not download module "vpc" ( source code from
"": error downloading
'ssh://': /usr/bin/git exited
with 128: Cloning into '.terraform/modules/vpc'...
Permission denied (publickey).

Locally I can do it without issues.
How should I configure the key in Jenkinsfile (or where else?) to allow access to the secondary repo?

I’ve seen this, this, this and this but cannot figure out how to connect it together.

Could anyone advise, please? Thank you.

As part of your pipeline, can you not download the module i.e. git clone it to a local directory and then in your code reference the module source locally and not via source = git@.
So you can do a checkout stage and specify the key in that via jenkins credentials.

Alternatively you can try the plugin, but I have not done this before so cant comment on how good it is.

I also found this which is relevant and

I would take the lazy option and checkout from git in an earlier stage in the pipeline and reference the module locally. i.e. checkout to mymodules/mod_repo then in source do source = ./mymodules/mod_repo or something along these lines