github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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: Explains the use of the source parameter, which tells Terraform where modules can be found. 6 --- 7 8 # Module Sources 9 10 As documented in the [Usage section](/docs/modules/usage.html), the only required parameter when using a module is `source`. The `source` parameter tells Terraform where the module can be found and what constraints to put on the module. Constraints can include a specific version or Git branch. 11 12 Terraform manages modules for you: it downloads them, organizes them on disk, checks for updates, etc. Terraform uses this `source` parameter to determine where it should retrieve and update modules from. 13 14 Terraform supports the following sources: 15 16 * Local file paths 17 18 * GitHub 19 20 * BitBucket 21 22 * Generic Git, Mercurial repositories 23 24 * HTTP URLs 25 26 * S3 buckets 27 28 Each is documented further below. 29 30 ## Local File Paths 31 32 The easiest source is the local file path. For maximum portability, this should be a relative file path into a subdirectory. This allows you to organize your Terraform configuration into modules within one repository, for example: 33 34 ``` 35 module "consul" { 36 source = "./consul" 37 } 38 ``` 39 40 Updates for file paths are automatic: when "downloading" the module using the [get command](/docs/commands/get.html), Terraform will create a symbolic link to the original directory. Therefore, any changes are automatically available. 41 42 ## GitHub 43 44 Terraform will automatically recognize GitHub URLs and turn them into a link to the specific Git repository. The syntax is simple: 45 46 ``` 47 module "consul" { 48 source = "github.com/hashicorp/example" 49 } 50 ``` 51 52 Subdirectories within the repository can also be referenced: 53 54 ``` 55 module "consul" { 56 source = "github.com/hashicorp/example//subdir" 57 } 58 ``` 59 60 These will fetch the modules using HTTPS. If you want to use SSH instead: 61 62 ``` 63 module "consul" { 64 source = "git@github.com:hashicorp/example.git//subdir" 65 } 66 ``` 67 68 **Note:** The double-slash, `//`, is important. It is what tells Terraform that that is the separator for a subdirectory, and not part of the repository itself. 69 70 GitHub source URLs require that Git is installed on your system and that you have access to the repository. 71 72 You can use the same parameters to GitHub repositories as you can generic Git repositories (such as tags or branches). See the documentation for generic Git repositories for more information. 73 74 ### Private GitHub Repos 75 76 If you need Terraform to be able to fetch modules from private GitHub repos on a remote machine (like Atlas or a CI server), you'll need to provide Terraform with credentials that can be used to authenticate as a user with read access to the private repo. 77 78 First, create a [machine user](https://developer.github.com/guides/managing-deploy-keys/#machine-users) on GitHub with read access to the private repo in question, then embed this user's credentials into the `source` parameter: 79 80 ``` 81 module "private-infra" { 82 source = "git::https://MACHINE-USER:MACHINE-PASS@github.com/org/privatemodules//modules/foo" 83 } 84 ``` 85 86 **Note:** Terraform does not yet support interpolations in the `source` field, so the machine username and password will have to be embedded directly into the `source` string. You can track [GH-1439](https://github.com/hashicorp/terraform/issues/1439) to learn when this limitation is addressed. 87 88 ## BitBucket 89 90 Terraform will automatically recognize BitBucket URLs and turn them into a link to the specific Git or Mercurial repository, for example: 91 92 ``` 93 module "consul" { 94 source = "bitbucket.org/hashicorp/consul" 95 } 96 ``` 97 98 Subdirectories within the repository can also be referenced: 99 100 ``` 101 module "consul" { 102 source = "bitbucket.org/hashicorp/consul//subdir" 103 } 104 ``` 105 106 **Note:** The double-slash, `//`, is important. It is what tells Terraform that this is the separator for a subdirectory, and not part of the repository itself. 107 108 BitBucket URLs will require that Git or Mercurial is installed on your system, depending on the type of repository. 109 110 ## Generic Git Repository 111 112 Generic Git repositories are also supported. The value of `source` in this case should be a complete Git-compatible URL. Using generic Git repositories requires that Git is installed on your system. 113 114 ``` 115 module "consul" { 116 source = "git://hashicorp.com/consul.git" 117 } 118 ``` 119 120 You can also use protocols such as HTTP or SSH to reference a module, but you'll have specify to Terraform that it is a Git module, by prefixing the URL with `git::` like so: 121 122 ``` 123 module "consul" { 124 source = "git::https://hashicorp.com/consul.git" 125 } 126 127 module "ami" { 128 source = "git::ssh://git@github.com/owner/repo.git" 129 } 130 ``` 131 132 If you do not specify the type of `source` then Terraform will attempt to use the closest match, for example assuming `https://hashicorp.com/consul.git` is a HTTP URL. 133 134 The URLs for Git repositories support the following query parameters: 135 136 * `ref` - The ref to checkout. This can be a branch, tag, commit, etc. 137 138 ``` 139 module "consul" { 140 source = "git::https://hashicorp.com/consul.git?ref=master" 141 } 142 ``` 143 144 ## Generic Mercurial Repository 145 146 Generic Mercurial repositories are supported. The value of `source` in this case should be a complete Mercurial-compatible URL. Using generic Mercurial repositories requires that Mercurial is installed on your system. You must tell Terraform that your `source` is a Mercurial repository by prefixing it with `hg::`. 147 148 ``` 149 module "consul" { 150 source = "hg::http://hashicorp.com/consul.hg" 151 } 152 ``` 153 154 URLs for Mercurial repositories support the following query parameters: 155 156 * `rev` - The rev to checkout. This can be a branch, tag, commit, etc. 157 158 ``` 159 module "consul" { 160 source = "hg::http://hashicorp.com/consul.hg?ref=master" 161 } 162 ``` 163 164 ## HTTP URLs 165 166 An HTTP or HTTPS URL can be used to redirect Terraform to get the module source from one of the other sources. For HTTP URLs, Terraform will make a `GET` request to the given URL. An additional `GET` parameter, `terraform-get=1`, will be appended, allowing 167 you to optionally render the page differently when Terraform is requesting it. 168 169 Terraform then looks for the resulting module URL in the following order: 170 171 1. Terraform will look to see if the header `X-Terraform-Get` is present. The header should contain the source URL of the actual module. 172 173 2. Terraform will look for a `<meta>` tag with the name of `terraform-get`, for example: 174 175 ``` 176 <meta name=“terraform-get” content="github.com/hashicorp/example" /> 177 ``` 178 179 ### S3 Bucket 180 181 Terraform can also store modules in an S3 bucket. To access the bucket 182 you must have appropriate AWS credentials in your configuration or 183 available via shared credentials or environment variables. 184 185 There are a variety of S3 bucket addressing schemes, most are 186 [documented in the S3 187 configuration](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro). 188 Here are a couple of examples. 189 190 Using the `s3` protocol. 191 192 ``` 193 module "consul" { 194 source = "s3::https://s3-eu-west-1.amazonaws.com/consulbucket/consul.zip" 195 } 196 ``` 197 198 Or directly using the bucket's URL. 199 200 ``` 201 module "consul" { 202 source = "consulbucket.s3-eu-west-1.amazonaws.com/consul.zip" 203 } 204 ``` 205 206 207 ## Unarchiving 208 209 Terraform will automatically unarchive files based on the extension of 210 the file being requested (over any protocol). It supports the following 211 archive formats: 212 213 * tar.gz and tgz 214 * tar.bz2 and tbz2 215 * zip 216 * gz 217 * bz2 218