github.com/hugorut/terraform@v1.1.3/website/docs/internals/provider-network-mirror-protocol.mdx (about) 1 --- 2 page_title: Provider Network Mirror Protocol 3 description: |- 4 The provider network mirror protocol is implemented by a server intending 5 to provide a mirror or read-through caching proxy for Terraform providers, 6 as an alternative distribution source from the provider's origin provider 7 registry. 8 --- 9 10 # Provider Network Mirror Protocol 11 12 -> Provider network mirrors are supported only in Terraform CLI v0.13.2 and later. Prior versions do not support this protocol. 13 14 The provider network mirror protocol is an optional protocol which you can 15 implement to provide an alternative installation source for Terraform providers, 16 regardless of their origin registries. 17 18 Terraform uses network mirrors only if you activate them explicitly in 19 [the CLI configuration's `provider_installation` block](/cli/config/config-file#provider-installation). 20 When enabled, a network mirror can serve providers belonging to any registry 21 hostname, which can allow an organization to serve all of the Terraform 22 providers they intend to use from an internal server, rather than from each 23 provider's origin registry. 24 25 This is _not_ the protocol that should be implemented by a host intending to 26 serve as an origin registry for Terraform Providers. To provide an origin 27 registry (whose hostname would then be included in the source addresses of the 28 providers it hosts), implement 29 [the provider registry protocol](/internals/provider-registry-protocol) 30 instead. 31 32 ## Provider Addresses 33 34 Each Terraform provider has an associated address which uniquely identifies it 35 within Terraform. A provider address has the syntax `hostname/namespace/type`, 36 which is described in more detail in 37 [the Provider Requirements documentation](/language/providers/requirements). 38 39 By default, the `hostname` portion of a provider address serves both as part 40 of its unique identifier _and_ as the location of the registry to retrieve it 41 from. However, when you configure Terraform to install providers from a network 42 mirror, the `hostname` serves _only_ as an identifier and no longer as 43 an installation source. A provider mirror can therefore serve providers 44 belonging to a variety of different provider registry hostnames, including 45 providers from the public Terraform Registry at `registry.terraform.io`, from a 46 single server. 47 48 In the relative URL patterns later in this document, the placeholder `:hostname` 49 refers to the hostname from the address of the provider being requested, not 50 the hostname where the provider network mirror is deployed. 51 52 ## Protocol Base URL 53 54 Most Terraform-native services use 55 [the remote service discovery protocol](/internals/remote-service-discovery) so 56 that the physical location of the endpoints can potentially be separated from 57 the hostname used in identifiers. The Provider Network Mirror protocol does 58 _not_ use the service discovery indirection, because a network mirror location 59 is only a physical location and is never used as part of the identifier of a 60 dependency in a Terraform configuration. 61 62 Instead, the provider installation section of the CLI configuration accepts 63 a base URL directly. The given URL must use the scheme `https:`, and should 64 end with a trailing slash so that the relative URLs of the individual operation 65 endpoints will be resolved beneath it. 66 67 ```hcl 68 provider_installation { 69 network_mirror { 70 url = "https://terraform.example.com/providers/" 71 } 72 } 73 ``` 74 75 Terraform uses the base URL only as a stem to resolve the operation endpoint 76 URLs against, and so it will never access the base URL directly. You can 77 therefore, if desired, publish human-readable usage documentation for your 78 network mirror at that URL. 79 80 The following sections describe the various operations that a provider 81 network mirror server must implement to be compatible with Terraform CLI's 82 provider installer. The indicated URLs are all relative to the given base URL, 83 as described above. 84 85 The URLs are shown with the convention that a path portion with a colon `:` 86 prefix is a placeholder for a dynamically-selected value, while all other 87 path portions are literal. For example, in `:hostname/:namespace/:type/index.json`, 88 the first three path portions are placeholders while the third is literally 89 the string "index.json". 90 91 The example requests in the following sections will assume the example mirror 92 base URL from the above CLI configuration example. 93 94 ### Authentication 95 96 If the CLI configuration includes 97 [credentials](/cli/config/config-file#credentials) for the hostname 98 given in the network mirror base URL, Terraform will include those credentials 99 in its requests for operations described below. 100 101 If the given URL uses a non-standard port number (other than 443) then the 102 credentials must be associated with a hostname that includes the port number, 103 such as `terraform.example.com:8443`. 104 105 Terraform does _not_ send credentials when retrieving the archives whose 106 URLs are given in the "List Available Installation Packages" response below. 107 If a particular mirror considers the distribution packages themselves to be 108 sensitive then it must use cryptographically-secure, user-specific, and 109 time-limited URLs in the metadata response. Strategies for doing so are out 110 of scope of this protocol documentation. 111 112 ## List Available Versions 113 114 This operation determines which versions are currently available for a 115 particular provider. 116 117 | Method | Path | Produces | 118 | ------ | --------------------------------------- | ------------------ | 119 | `GET` | `:hostname/:namespace/:type/index.json` | `application/json` | 120 121 ### Parameters 122 123 * `hostname` (required): the hostname portion of the address of the requested 124 provider. 125 * `namespace` (required): the namespace portion of the address of the requested 126 provider. 127 * `type` (required): the type portion of the address of the requested provider. 128 129 ### Sample Request 130 131 ``` 132 curl 'https://terraform.example.com/providers/registry.terraform.io/hashicorp/random/index.json' 133 ``` 134 135 ### Sample Response 136 137 ```json 138 { 139 "versions": { 140 "2.0.0": {}, 141 "2.0.1": {} 142 } 143 } 144 ``` 145 146 ### Response Properties 147 148 A successful result is a JSON object containing a single property `versions`, 149 which must be a JSON object. 150 151 Each of the property names of the `versions` object represents an available 152 version number. The property values must be objects, but no properties are 153 currently defined for those objects. Future versions of this protocol may 154 define optional per-version properties for Terraform to use as installation 155 hints, so implementations of the current version should leave those objects 156 empty. 157 158 Return `404 Not Found` to signal that the mirror does not have a provider 159 with the given address. 160 161 ## List Available Installation Packages 162 163 This operation returns download URLs and associated metadata for the 164 distribution packages for a particular version of a provider. 165 166 Each distribution package is associated with a particular operating system 167 and architecture. A network mirror may host only a subset of the available 168 packages for a provider version, if the users of the mirror are known to all 169 use only a subset of the target platforms that Terraform supports. 170 171 Terraform CLI uses this operation after it has selected the newest available 172 version matching the configured version constraints, in order to find a zip 173 archive containing the plugin itself. 174 175 | Method | Path | Produces | 176 | ------ | ------------------------------------------ | ------------------ | 177 | `GET` | `:hostname/:namespace/:type/:version.json` | `application/json` | 178 179 ### Parameters 180 181 * `hostname` (required): the hostname portion of the address of the requested 182 provider. 183 * `namespace` (required): the namespace portion of the address of the requested 184 provider. 185 * `type` (required): the type portion of the address of the requested provider. 186 * `version` (required): the version selected to download. This will exactly 187 match one of the version strings returned from a previous call to 188 [List Available Versions](#list-available-versions). 189 190 ### Sample Request 191 192 ``` 193 curl 'https://terraform.example.com/providers/registry.terraform.io/hashicorp/random/2.0.0.json' 194 ``` 195 196 ### Sample Response 197 198 ```json 199 { 200 "archives": { 201 "darwin_amd64": { 202 "url": "terraform-provider-random_2.0.0_darwin_amd64.zip", 203 "hashes": [ 204 "h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=" 205 ] 206 }, 207 "linux_amd64": { 208 "url": "terraform-provider-random_2.0.0_linux_amd64.zip", 209 "hashes": [ 210 "h1:lCJCxf/LIowc2IGS9TPjWDyXY4nOmdGdfcwwDQCOURQ=" 211 ] 212 } 213 } 214 } 215 ``` 216 217 ### Response Properties 218 219 A successful result is a JSON object with a property called `archives`, which 220 must be a JSON object. 221 222 Each of the property names of the `archives` object is a target platform 223 identifier, which consists of an operating system and architecture concatenated 224 with an underscore (`_`). 225 226 Each property value in the `archives` object is itself a nested object with 227 the following properties: 228 229 * `url` (required): a string specifying the URL from which Terraform should 230 download the `.zip` archive containing the requested provider plugin version. 231 232 Terraform resolves the URL relative to the URL from which the current 233 JSON document was returned, so the examples above containing only a 234 filename would cause Terraform to construct a URL like: 235 236 ``` 237 https://terraform.example.com/providers/registry.terraform.io/hashicorp/random/terraform-provider-random_2.0.0_darwin_amd64.zip 238 ``` 239 240 * `hashes` (optional): a JSON array of strings containing one or more hash 241 values for the indicated archive. These hashes use Terraform's provider 242 package hashing algorithm. At present, the easiest way to populate these 243 is to construct a mirror's JSON indices using the `terraform providers mirror` 244 command, as described in a later section, which will include the calculated 245 hashes of each provider. 246 247 If the response includes at least one hash, Terraform will select the hash 248 whose algorithm it considers to be strongest and verify that the downloaded 249 package matches that hash. If the response does not include a `hashes` 250 property then Terraform will install the indicated archive with no 251 verification. 252 253 Terraform CLI will only attempt to download versions that it has previously 254 seen in response to [List Available Versions](#list-available-versions). 255 256 ## Provider Mirror as a Static Website 257 258 The provider mirror protocol is designed so that it can potentially be implemented 259 by placing files on typical static website hosting services. When using this 260 strategy, implement the JSON index responses described above as `.json` files 261 in the appropriate nested subdirectories, and ensure that your system is 262 configured to serve `.json` files with the `application/json` media type. 263 264 As a convenience, Terraform CLI includes 265 [the `terraform providers mirror` subcommand](/cli/commands/providers/mirror), 266 which will analyze the current configuration for the providers it requires, 267 download the packages for those providers from their origin registries, and 268 place them into a local directory suitable for use as a mirror. 269 270 The `terraform providers mirror` subcommand also generates `index.json` and 271 version-specific `.json` files that can, when placed in a static website hosting 272 system, produce responses compatible with the provider mirror protocol. 273 274 If you wish to create a mirror with providers for a number of different 275 Terraform configurations, run `terraform providers mirror` in each configuration 276 in turn while providing the same output directory each time. Terraform will 277 then merge together all of the requirements into a single set of JSON indices.