1

I am making a jenkins pipeline job, which call jenkins file , inside that i m calling terraform.sh file with CredentialsBinding . when i m running the i m getting below error in terraform init.

 Getting source "git::ssh://git@gitlab.com/****/terraform-modules.git//pre-production?ref=0.0.1"
Error downloading modules: Error loading modules: error downloading 'ssh://git@gitlab.com/****/terraform-modules.git?ref=0.0.1': /usr/bin/git exited with 128: Cloning into '.terraform/modules/515fc2bd0e7790ab33b22f826cd0173b'...
Permission denied (publickey).
fatal: Could not read from remote repository.
  • 1
    Possible duplicate of [GitHub Error Message - Permission denied (publickey)](https://stackoverflow.com/questions/12940626/github-error-message-permission-denied-publickey) – vahdet Dec 12 '18 at 13:08

1 Answers1

0

This isn't a Terraform or a Jenkins issue but rather a Git authentication issue.

The ssh part of the Git repo address indicates that you need to have an SSH key pair configured to access that repo. You will need to configure things on both the Git repo and on the Jenkins server. See the Gitlab docs for more info.

Now if the repo were public, you could forego the SSH config and switch the Git repo URL to use HTTPS. e.g.:

https://gitlab.com/****/terraform-modules.git

And if you're worried about security, you could always put a firewall in front of the Gitlab server and restrict access to only your Jenkins server(s).

Hope this helps!

KJH
  • 2,382
  • 16
  • 26
  • I don't want to configure ssh key on repo. I just want to pass SSH User Private Key which is on Jenkins to .sh file so that repo can use that SSH User Private . What are the possibility. I tried using access token in terraform source module which get failed to pull git Lab . – Ravi Jaisawal Dec 13 '18 at 06:54
  • SSH is based on public-key crypto which means that you need a pair of keys, 1 public and 1 private. One of those keys goes on 1 side of the connection with the other key on the other side. – KJH Dec 13 '18 at 15:59