2

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://git@bitbucket.org: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://git@bitbucket.org:<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?

Blokje5
  • 4,763
  • 1
  • 20
  • 37

3 Answers3

3

Change the colon between ssh://git@bitbucket.org and username/repo to a slash:

ssh://git@bitbucket.org/username/repo

In that format, the colon indicates an alternate port - useful if you want to do ssh://git@altssh.bitbucket.org:443/username/repo, and similar to how you'd specify an alternate port for other protocols like HTTP.

Jim Redmond
  • 4,139
  • 1
  • 14
  • 18
  • Is it possible to make it generic so that all team members could use it? Like using some env variables? – Ankur Bhatia Aug 21 '20 at 09:48
  • 1
    Both of these forms are already generic. The `username` listed here is the *owner* of the repo, which could be a team or individual; changing the `username` will send requests to a different repo. – Jim Redmond Oct 10 '20 at 18:06
1

Use this if you need to reference a specific tag in your repo. Please note that the module name can be a path to your module or submodules directory e.g module/submodule

source = "git@bitbucket.org:username/reponame.git//modulename?ref=tagvalue"
MoFoLuWaSo
  • 1,289
  • 1
  • 5
  • 6
0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250