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