Terrafrom/Jenkins CI/CD with modules from private repo (ssh-key)


I have been using terrafrom for quite some time now and I really love it. I am also familiar with terraform-cloud. Recently I have started working on a Jenkins private CI/CD pipeline and it seems I am missing something. I am also familiar with Jenkins and its “credentials” structure etc.

However I have the following problem, for which it seems I am not able to find a suitable solution. We are using terraform from private repository. The main code is in one repo and the child module are separate in different repos. In the main terrafomr code the child modules are called like this:

module "s3-test" { source = "git::ssh://git@stash.prod.tis.loc:12345/s3.git" }

I would like to mention that I have configured jenkins with credentials and ssh-key to be able to pull the main repo, but during “terrafrom init” - it is not able to pull the child modules because of SSH-KEY access permission.

Can we provide via command like to terrafrom what ssh-key to use for that ? Anyone had this problem ? There is something like a solution here, but I do not much like it:

Thank you in advance.