github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/website/source/docs/modules/sources.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Module Sources"
     4  sidebar_current: "docs-modules-sources"
     5  description: |-
     6    As documented in usage, the only required parameter when using a module is the `source` parameter which tells Terraform where the module can be found and what constraints to put on the module if any (such as branches for Git, versions, etc.).
     7  ---
     8  
     9  # Module Sources
    10  
    11  As documented in [usage](/docs/modules/usage.html), the only required
    12  parameter when using a module is the `source` parameter which tells Terraform
    13  where the module can be found and what constraints to put on the module
    14  if any (such as branches for Git, versions, etc.).
    15  
    16  Terraform manages modules for you: it downloads them, organizes them
    17  on disk, checks for updates, etc. Terraform uses this source parameter for
    18  the download/update of modules.
    19  
    20  Terraform supports the following sources:
    21  
    22    * Local file paths
    23  
    24    * GitHub
    25  
    26    * BitBucket
    27  
    28    * Generic Git, Mercurial repositories
    29  
    30    * HTTP URLs
    31  
    32  Each is documented further below.
    33  
    34  ## Local File Paths
    35  
    36  The easiest source is the local file path. For maximum portability, this
    37  should be a relative file path into a subdirectory. This allows you to
    38  organize your Terraform configuration into modules within one repository,
    39  for example.
    40  
    41  An example is shown below:
    42  
    43  ```
    44  module "consul" {
    45  	source = "./consul"
    46  }
    47  ```
    48  
    49  Updates for file paths are automatic: when "downloading" the module
    50  using the [get command](/docs/commands/get.html), Terraform will create
    51  a symbolic link to the original directory. Therefore, any changes are
    52  automatically instantly available.
    53  
    54  ## GitHub
    55  
    56  Terraform will automatically recognize GitHub URLs and turn them into
    57  the proper Git repository. The syntax is simple:
    58  
    59  ```
    60  module "consul" {
    61  	source = "github.com/hashicorp/example"
    62  }
    63  ```
    64  
    65  Subdirectories within the repository can also be referenced:
    66  
    67  ```
    68  module "consul" {
    69  	source = "github.com/hashicorp/example//subdir"
    70  }
    71  ```
    72  
    73  **Note:** The double-slash is important. It is what tells Terraform that
    74  that is the separator for a subdirectory, and not part of the repository
    75  itself.
    76  
    77  GitHub source URLs will require that Git is installed on your system
    78  and that you have the proper access to the repository.
    79  
    80  You can use the same parameters to GitHub repositories as you can generic
    81  Git repositories (such as tags or branches). See the documentation for generic
    82  Git repositories for more information.
    83  
    84  #### Private GitHub Repos<a id="private-github-repos"></a>
    85  
    86  If you need Terraform to be able to fetch modules from private GitHub repos on
    87  a remote machine (like a Atlas or a CI server), you'll need to provide
    88  Terraform with credentials that can be used to authenticate as a user with read
    89  access to the private repo.
    90  
    91  First, create a [machine
    92  user](https://developer.github.com/guides/managing-deploy-keys/#machine-users)
    93  with access to read from the private repo in question, then embed this user's
    94  credentials into the source field:
    95  
    96  ```
    97  module "private-infra" {
    98    source = "git::https://MACHINE-USER:MACHINE-PASS@github.com/org/privatemodules//modules/foo"
    99  }
   100  ```
   101  
   102  Note that Terraform does not yet support interpolations in the `source` field,
   103  so the machine username and password will have to be embedded directly into the
   104  source string. You can track
   105  [GH-1439](https://github.com/hashicorp/terraform/issues/1439) to learn when this
   106  limitation is lifted.
   107  
   108  ## BitBucket
   109  
   110  Terraform will automatically recognize BitBucket URLs and turn them into
   111  the proper Git or Mercurial repository. An example:
   112  
   113  ```
   114  module "consul" {
   115  	source = "bitbucket.org/hashicorp/example"
   116  }
   117  ```
   118  
   119  Subdirectories within the repository can also be referenced:
   120  
   121  ```
   122  module "consul" {
   123  	source = "bitbucket.org/hashicorp/example//subdir"
   124  }
   125  ```
   126  
   127  **Note:** The double-slash is important. It is what tells Terraform that
   128  that is the separator for a subdirectory, and not part of the repository
   129  itself.
   130  
   131  BitBucket URLs will require that Git or Mercurial is installed on your
   132  system, depending on the source URL.
   133  
   134  ## Generic Git Repository
   135  
   136  Generic Git repositories are also supported. The value of `source` in this
   137  case should be a complete Git-compatible URL. Using Git requires that
   138  Git is installed on your system. Example:
   139  
   140  ```
   141  module "consul" {
   142  	source = "git://hashicorp.com/module.git"
   143  }
   144  ```
   145  
   146  You can also use protocols such as HTTP or SSH, but you'll have to hint
   147  to Terraform (using the forced source type syntax documented below) to use
   148  Git:
   149  
   150  ```
   151  // force https source
   152  module "consul" {
   153  	source = "git::https://hashicorp.com/module.git"
   154  }
   155  
   156  // force ssh source
   157  module "ami" {
   158  	source = "git::ssh://git@github.com/owner/repo.git"
   159  }
   160  ```
   161  
   162  URLs for Git repositories (of any protocol) support the following query
   163  parameters:
   164  
   165    * `ref` - The ref to checkout. This can be a branch, tag, commit, etc.
   166  
   167  An example of using these parameters is shown below:
   168  
   169  ```
   170  module "consul" {
   171  	source = "git::https://hashicorp.com/module.git?ref=master"
   172  }
   173  ```
   174  
   175  ## Generic Mercurial Repository
   176  
   177  Generic Mercurial repositories are supported. The value of `source` in this
   178  case should be a complete Mercurial-compatible URL. Using Mercurial requires that
   179  Mercurial is installed on your system. Example:
   180  
   181  ```
   182  module "consul" {
   183  	source = "hg::http://hashicorp.com/module.hg"
   184  }
   185  ```
   186  
   187  In the case of above, we used the forced source type syntax documented below.
   188  Mercurial repositories require this.
   189  
   190  URLs for Mercurial repositories (of any protocol) support the following query
   191  parameters:
   192  
   193    * `rev` - The rev to checkout. This can be a branch, tag, commit, etc.
   194  
   195  ## HTTP URLs
   196  
   197  Any HTTP endpoint can serve up Terraform modules. For HTTP URLs (SSL is
   198  supported, as well), Terraform will make a GET request to the given URL.
   199  An additional GET parameter `terraform-get=1` will be appended, allowing
   200  you to optionally render the page differently when Terraform is requesting it.
   201  
   202  Terraform then looks for the resulting module URL in the following order.
   203  
   204  First, if a header `X-Terraform-Get` is present, then it should contain
   205  the source URL of the actual module. This will be used.
   206  
   207  If the header isn't present, Terraform will look for a `<meta>` tag
   208  with the name of "terraform-get". The value will be used as the source
   209  URL.
   210  
   211  ## Forced Source Type
   212  
   213  In a couple places above, we've referenced "forced source type." Forced
   214  source type is a syntax added to URLs that allow you to force a specific
   215  method for download/updating the module. It is used to disambiguate URLs.
   216  
   217  For example, the source "http://hashicorp.com/foo.git" could just as
   218  easily be a plain HTTP URL as it might be a Git repository speaking the
   219  HTTP protocol. The forced source type syntax is used to force Terraform
   220  one way or the other.
   221  
   222  Example:
   223  
   224  ```
   225  module "consul" {
   226  	source = "git::http://hashicorp.com/foo.git"
   227  }
   228  ```
   229  
   230  The above will force Terraform to get the module using Git, despite it
   231  being an HTTP URL.
   232  
   233  If a forced source type isn't specified, Terraform will match the exact
   234  protocol if it supports it. It will not try multiple methods. In the case
   235  above, it would've used the HTTP method.