title: Terraform module in github private repo
body: <p>I am trying to use my private git repo as source for the terraform modules.</p>
  
  <p>ssh public key has been copied over to github. </p>
  
  <p>Tried following options as source but nothing worked:</p>
  
  <ul>
  <li>git::git@github.com:/terraform-modules//sub-dir</li>
  <li>github.com/terraform-modules//sub-dir</li>
  <li>git@github.com:/terraform-modules//sub-dir</li>
  <li>git::<a href="https://MACHINE-USER:MACHINE-PASS@github.com/terraform-modules//sub-dir" rel="noreferrer">https://MACHINE-USER:MACHINE-PASS@github.com/terraform-modules//sub-dir</a></li>
  <li>git::<a href="https://github.com/" rel="noreferrer">https://github.com/</a>/terraform-modules.git//subdir</li>
  <li><a href="https://GIT_HUB_PAT@github.com/terraform-modules.git//subdir" rel="noreferrer">https://GIT_HUB_PAT@github.com/terraform-modules.git//subdir</a></li>
  </ul>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Referring to Private Github repos section on the following link didn't help either.
  <a href="https://github.com/alibaba/terraform-provider/blob/master/vendor/github.com/hashicorp/terraform/website/docs/modules/sources.html.markdown" rel="noreferrer">https://github.com/alibaba/terraform-provider/blob/master/vendor/github.com/hashicorp/terraform/website/docs/modules/sources.html.markdown</a></p>
  
  <p>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.</p>
  
  <p>If you run Terraform only on your local machine, you can specify the module source as an SSH URI (like git@github.com:hashicorp/example.git) and Terraform will use your default SSH key to authenticate.</p>
  
  <p>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.</p>
  
  <p>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 <strong><em>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::<a href="https://MACHINE-USER:MACHINE-PASS@github.com/org/privatemodules//modules/foo" rel="noreferrer">https://MACHINE-USER:MACHINE-PASS@github.com/org/privatemodules//modules/foo</a>"
  }</em></strong>
  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.</p>