github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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 **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. 61 62 GitHub source URLs require that Git is installed on your system and that you have access to the repository. 63 64 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. 65 66 ### Private GitHub Repos 67 68 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. 69 70 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: 71 72 ``` 73 module "private-infra" { 74 source = "git::https://MACHINE-USER:MACHINE-PASS@github.com/org/privatemodules//modules/foo" 75 } 76 ``` 77 78 **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. 79 80 ## BitBucket 81 82 Terraform will automatically recognize BitBucket URLs and turn them into a link to the specific Git or Mercurial repository, for example: 83 84 ``` 85 module "consul" { 86 source = "bitbucket.org/hashicorp/consul" 87 } 88 ``` 89 90 Subdirectories within the repository can also be referenced: 91 92 ``` 93 module "consul" { 94 source = "bitbucket.org/hashicorp/consul//subdir" 95 } 96 ``` 97 98 **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. 99 100 BitBucket URLs will require that Git or Mercurial is installed on your system, depending on the type of repository. 101 102 ## Generic Git Repository 103 104 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. 105 106 ``` 107 module "consul" { 108 source = "git://hashicorp.com/consul.git" 109 } 110 ``` 111 112 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: 113 114 ``` 115 module "consul" { 116 source = "git::https://hashicorp.com/consul.git" 117 } 118 119 module "ami" { 120 source = "git::ssh://git@github.com/owner/repo.git" 121 } 122 ``` 123 124 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. 125 126 The URLs for Git repositories support the following query parameters: 127 128 * `ref` - The ref to checkout. This can be a branch, tag, commit, etc. 129 130 ``` 131 module "consul" { 132 source = "git::https://hashicorp.com/consul.git?ref=master" 133 } 134 ``` 135 136 ## Generic Mercurial Repository 137 138 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::`. 139 140 ``` 141 module "consul" { 142 source = "hg::http://hashicorp.com/consul.hg" 143 } 144 ``` 145 146 URLs for Mercurial repositories support the following query parameters: 147 148 * `rev` - The rev to checkout. This can be a branch, tag, commit, etc. 149 150 ``` 151 module "consul" { 152 source = "hg::http://hashicorp.com/consul.hg?ref=master" 153 } 154 ``` 155 156 ## HTTP URLs 157 158 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 159 you to optionally render the page differently when Terraform is requesting it. 160 161 Terraform then looks for the resulting module URL in the following order: 162 163 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. 164 165 2. Terraform will look for a `<meta>` tag with the name of `terraform-get`, for example: 166 167 ``` 168 <meta name=“terraform-get” content="github.com/hashicorp/example" /> 169 ``` 170 171 ### S3 Bucket 172 173 Terraform can also store modules in an S3 bucket. To access the bucket 174 you must have appropriate AWS credentials in your configuration or 175 available via shared credentials or environment variables. 176 177 There are a variety of S3 bucket addressing schemes, most are 178 [documented in the S3 179 configuration](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro). 180 Here are a couple of examples. 181 182 Using the `s3` protocol. 183 184 ``` 185 module "consul" { 186 source = "s3::https://s3-eu-west-1.amazonaws.com/consulbucket/consul.zip" 187 } 188 ``` 189 190 Or directly using the bucket's URL. 191 192 ``` 193 module "consul" { 194 source = "consulbucket.s3-eu-west-1.amazonaws.com/consul.zip" 195 } 196 ``` 197 198 199 ## Unarchiving 200 201 Terraform will automatically unarchive files based on the extension of 202 the file being requested (over any protocol). It supports the following 203 archive formats: 204 205 * tar.gz and tgz 206 * tar.bz2 and tbz2 207 * zip 208 * gz 209 * bz2 210