I am trying to use my private git repo as source for the terraform modules.
ssh public key has been copied over to github.
Tried following options as source but nothing worked:
- git::[email protected]:/terraform-modules//sub-dir
- github.com/terraform-modules//sub-dir
- [email protected]:/terraform-modules//sub-dir
- git::https://MACHINE-USER:[email protected]/terraform-modules//sub-dir
- git::https://github.com//terraform-modules.git//subdir
- https://[email protected]/terraform-modules.git//subdir
Any help is greatly appreciated.
Referring to Private Github repos section on the following link didn't help either. https://github.com/alibaba/terraform-provider/blob/master/vendor/github.com/hashicorp/terraform/website/docs/modules/sources.html.markdown
Private GitHub Repos If you need Terraform to fetch modules from private GitHub repos, you must provide Terraform with credentials to authenticate as a user with read access to those repos.
If you run Terraform only on your local machine, you can specify the module source as an SSH URI (like [email protected]:hashicorp/example.git) and Terraform will use your default SSH key to authenticate.
If you use Terraform Enterprise, you can use SSH URIs. You'll need to add an SSH private key to your organization and assign it to any workspace that fetches modules from private repos. See the Terraform Enterprise docs about SSH keys for cloning modules.
If you need to run Terraform on a remote machine like a CI worker, you either need to write an SSH key to disk and set the GIT_SSH_COMMAND environment variable appropriately during the worker's provisioning process, or create a GitHub machine user with read access to the repos in question and embed its credentials into the modules' source parameters: module "private-infra" { source = "git::https://MACHINE-USER:[email protected]/org/privatemodules//modules/foo" } Note that Terraform does not support interpolations in the source parameter of a module, so you must hardcode the machine username and password if using this method.