2
votes

When calling a module over from a local source everything went alright, however I decided to refactor the Terraform code to use a git repository for modules.

I created a new repository in our BitBucket account with the name terraform-modules, and refactored the source attribute of the modules to have the following structure:

source     = "git::ssh://[email protected]:carepaydev/terraform-modules.git//modules/iam/iam_roles/assumable_role"

When calling terraform init I get the following error:

Error downloading modules: Error loading modules: error downloading 'ssh://[email protected]:<username>/terraform-modules.git': /usr/local/bin/git exited with 128: Cloning into '.terraform/modules/caf541f5e5ccbb1d204bce3b94091014'...
ssh: Could not resolve hostname bitbucket.org:<username>: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Cloning the repository using git clone does work. I tried setting the TF_LOG env var to TRACE to see if that would give me more insight, but that did not help.

Any clue why this fails?

2

2 Answers

2
votes

Change the colon between ssh://[email protected] and username/repo to a slash:

ssh://[email protected]/username/repo

In that format, the colon indicates an alternate port - useful if you want to do ssh://[email protected]:443/username/repo, and similar to how you'd specify an alternate port for other protocols like HTTP.

0
votes

You have a similar error with hashicorp/terraform issue 12696, when trying to access a private repository.

At least, try and set git config --global core.sshCommand "ssh -Tvv", in order to see what private key is actually used by Terraform durong the git clone process.