github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/website/docs/internals/module-registry-protocol.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Module Registry Protocol" 4 sidebar_current: "docs-internals-module-registry-protocol" 5 description: |- 6 The module registry protocol is implemented by a host intending to be the 7 host of one or more Terraform modules, specifying which modules are available 8 and where to find their distribution packages. 9 --- 10 11 # Module Registry Protocol 12 13 -> Third-party module registries are supported only in Terraform CLI 0.11 and later. Prior versions do not support this protocol. 14 15 The module registry protocol is what Terraform CLI uses to discover metadata 16 about modules available for installation and to locate the distribution 17 package for a selected module. 18 19 The primary implementation of this protocol is the public 20 [Terraform Registry](https://registry.terraform.io/) at `registry.terraform.io`. 21 By writing and deploying your own implementation of this protocol, you can 22 create a separate registry to distribute your own modules, as an alternative to 23 publishing them on the public Terraform Registry. 24 25 The public Terraform Registry implements a superset of the API described on 26 this page, in order to capture additional information used in the registry UI. 27 For information on those extensions, see 28 [Terraform Registry HTTP API](/docs/registry/api.html). Third-party registry 29 implementations may choose to implement those extensions if desired, but 30 Terraform CLI itself does not use them. 31 32 ## Module Addresses 33 34 Each Terraform module has an associated address. A module address has the 35 syntax `hostname/namespace/name/system`, where: 36 37 * `hostname` is the hostname of the module registry that serves this module. 38 * `namespace` is the name of a namespace, unique on a particular hostname, that 39 can contain one or more modules that are somehow related. On the public 40 Terraform Registry the "namespace" represents the organization that is 41 packaging and distributing the module. 42 * `name` is the module name, which generally names the abstraction that the 43 module is intending to create. 44 * `system` is the name of a remote system that the module is primarily written 45 to target. For multi-cloud abstractions, there can be multiple modules with 46 addresses that differ only in "system" to reflect provider-specific 47 implementations of the abstraction, like 48 `registry.terraform.io/hashicorp/consul/aws` vs. 49 `registry.terraform.io/hashicorp/consul/azurerm`. The system name commonly 50 matches the type portion of the address of an official provider, like `aws` 51 or `azurerm` in the above examples, but that is not required and so you can 52 use whichever system keywords make sense for the organization of your 53 particular registry. 54 55 The `hostname/` portion of a module address (including its slash delimiter) 56 is optional, and if omitted defaults to `registry.terraform.io/`. 57 58 For example: 59 60 * `hashicorp/consul/aws` is a shorthand for 61 `registry.terraform.io/hashicorp/consul/aws`, which is a module on the 62 public registry for deploying Consul clusters in Amazon Web Services. 63 * `example.com/awesomecorp/consul/happycloud` is a hypothetical module published 64 on a third-party registry. 65 66 If you intend to share a module you've developed for use by all Terraform 67 users, please consider publishing it into the public 68 [Terraform Registry](https://registry.terraform.io/) to make your module more 69 discoverable. You only need to implement this module registry protocol if you 70 wish to publish modules whose addresses include a different hostname that is 71 under your control. 72 73 ## Module Versions 74 75 Each distinct module address has associated with it a set of versions, each 76 of which has an associated version number. Terraform assumes version numbers 77 follow the [Semantic Versioning 2.0](https://semver.org/) conventions, with 78 the user-facing behavior of the module serving as the "public API". 79 80 Each `module` block may select a distinct version of a module, even if multiple 81 blocks have the same source address. 82 83 ## Service Discovery 84 85 The module registry protocol begins with Terraform CLI using 86 [Terraform's remote service discovery protocol](./remote-service-discovery.html), 87 with the hostname in the module address acting as the "User-facing Hostname". 88 89 The service identifier for the module registry protocol is `modules.v1`. 90 Its associated string value is the base URL for the relative URLs defined in 91 the sections that follow. 92 93 For example, the service discovery document for a host that _only_ implements 94 the module registry protocol might contain the following: 95 96 ```json 97 { 98 "modules.v1": "/terraform/modules/v1/" 99 } 100 ``` 101 102 If the given URL is a relative URL then Terraform will interpret it as relative 103 to the discovery document itself. The specific module registry protocol 104 endpoints are defined as URLs relative to the given base URL, and so the 105 specified base URL should generally end with a slash to ensure that those 106 relative paths will be resolved as expected. 107 108 The following sections describe the various operations that a module 109 registry must implement to be compatible with Terraform CLI's module 110 installer. The indicated URLs are all relative to the URL resulting from 111 service discovery, as described above. We use the current URLs on 112 Terraform Registry as working examples, assuming that the caller already 113 performed service discovery on `registry.terraform.io` to learn the base URL. 114 115 The URLs are shown with the convention that a path portion with a colon `:` 116 prefix is a placeholder for a dynamically-selected value, while all other 117 path portions are literal. For example, in `:namespace/:type/versions`, 118 the first two path portions are placeholders while the third is literally 119 the string "versions". 120 121 ## List Available Versions for a Specific Module 122 123 This is the primary endpoint for resolving module sources, returning the 124 available versions for a given fully-qualified module. 125 126 | Method | Path | Produces | 127 | ------ | ------------------------------------- | -------------------------- | 128 | `GET` | `:namespace/:name/:provider/versions` | `application/json` | 129 130 ### Parameters 131 132 - `namespace` `(string: <required>)` - The user or organization the module is 133 owned by. This is required and is specified as part of the URL path. 134 135 - `name` `(string: <required>)` - The name of the module. 136 This is required and is specified as part of the URL path. 137 138 - `system` `(string: <required>)` - The name of the target system. 139 This is required and is specified as part of the URL path. 140 141 ### Sample Request 142 143 ```text 144 $ curl 'https://registry.terraform.io/v1/modules/hashicorp/consul/aws/versions' 145 ``` 146 147 ### Sample Response 148 149 The `modules` array in the response always includes the requested module as the 150 first element. 151 152 Other elements of this list are not currently used. Third-party implementations 153 should always use a single-element list for forward compatiblity with possible 154 future extensions to the protocol. 155 156 Each returned module has an array of available versions, which Terraform 157 matches against any version constraints given in configuration. 158 159 ```json 160 { 161 "modules": [ 162 { 163 "versions": [ 164 {"version": "1.0.0"}, 165 {"version": "1.1.0"}, 166 {"version": "2.0.0"} 167 ] 168 } 169 ] 170 } 171 ``` 172 173 Return `404 Not Found` to indicate that no module is available with the 174 requested namespace, name, and provider 175 176 ## Download Source Code for a Specific Module Version 177 178 This endpoint downloads the specified version of a module for a single provider. 179 180 | Method | Path | Produces | 181 | ------ | ------------------------------------------------------ | -------------------------- | 182 | `GET` | `:namespace/:name/:system/:version/download` | `application/json` | 183 184 ### Parameters 185 186 - `namespace` `(string: <required>)` - The user the module is owned by. 187 This is required and is specified as part of the URL path. 188 189 - `name` `(string: <required>)` - The name of the module. 190 This is required and is specified as part of the URL path. 191 192 - `provider` `(string: <required>)` - The name of the target system. 193 This is required and is specified as part of the URL path. 194 195 - `version` `(string: <required>)` - The version of the module. 196 This is required and is specified as part of the URL path. 197 198 ### Sample Request 199 200 ```text 201 $ curl -i 'https://registry.terraform.io/v1/modules/hashicorp/consul/aws/0.0.1/download' 202 ``` 203 204 ### Sample Response 205 206 ```text 207 HTTP/1.1 204 No Content 208 Content-Length: 0 209 X-Terraform-Get: https://api.github.com/repos/hashicorp/terraform-aws-consul/tarball/v0.0.1//*?archive=tar.gz 210 ``` 211 212 A successful response has no body, and includes the location from which the 213 module version's source can be downloaded in the `X-Terraform-Get` header. 214 The value of this header accepts the same values as the `source` argument 215 in a `module` block in Terraform configuration, as described in 216 [Module Sources](https://www.terraform.io/docs/language/modules/sources.html), 217 except that it may not recursively refer to another module registry address. 218 219 The value of `X-Terraform-Get` may instead be a relative URL, indicated by 220 beginning with `/`, `./` or `../`, in which case it is resolved relative to 221 the full URL of the download endpoint to produce 222 [an HTTP URL module source](/docs/language/modules/sources.html#http-urls).