github.com/pulumi/terraform@v1.4.0/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 defined for those objects. We recommend leaving those objects empty for forward compatibility.
   153  
   154  Return `404 Not Found` to signal that the mirror does not have a provider
   155  with the given address.
   156  
   157  ## List Available Installation Packages
   158  
   159  This operation returns download URLs and associated metadata for the
   160  distribution packages for a particular version of a provider.
   161  
   162  Each distribution package is associated with a particular operating system
   163  and architecture. A network mirror may host only a subset of the available
   164  packages for a provider version, if the users of the mirror are known to all
   165  use only a subset of the target platforms that Terraform supports.
   166  
   167  Terraform CLI uses this operation after it has selected the newest available
   168  version matching the configured version constraints, in order to find a zip
   169  archive containing the plugin itself.
   170  
   171  | Method | Path                                       | Produces           |
   172  | ------ | ------------------------------------------ | ------------------ |
   173  | `GET`  | `:hostname/:namespace/:type/:version.json` | `application/json` |
   174  
   175  ### Parameters
   176  
   177  * `hostname` (required): the hostname portion of the address of the requested
   178    provider.
   179  * `namespace` (required): the namespace portion of the address of the requested
   180    provider.
   181  * `type` (required): the type portion of the address of the requested provider.
   182  * `version` (required): the version selected to download. This will exactly
   183    match one of the version strings returned from a previous call to
   184    [List Available Versions](#list-available-versions).
   185  
   186  ### Sample Request
   187  
   188  ```
   189  curl 'https://terraform.example.com/providers/registry.terraform.io/hashicorp/random/2.0.0.json'
   190  ```
   191  
   192  ### Sample Response
   193  
   194  ```json
   195  {
   196    "archives": {
   197      "darwin_amd64": {
   198        "url": "terraform-provider-random_2.0.0_darwin_amd64.zip",
   199        "hashes": [
   200          "h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs="
   201        ]
   202      },
   203      "linux_amd64": {
   204        "url": "terraform-provider-random_2.0.0_linux_amd64.zip",
   205        "hashes": [
   206          "h1:lCJCxf/LIowc2IGS9TPjWDyXY4nOmdGdfcwwDQCOURQ="
   207        ]
   208      }
   209    }
   210  }
   211  ```
   212  
   213  ### Response Properties
   214  
   215  A successful result is a JSON object with a property called `archives`, which
   216  must be a JSON object.
   217  
   218  Each of the property names of the `archives` object is a target platform
   219  identifier, which consists of an operating system and architecture concatenated
   220  with an underscore (`_`).
   221  
   222  Each property value in the `archives` object is itself a nested object with
   223  the following properties:
   224  
   225  * `url` (required): a string specifying the URL from which Terraform should
   226    download the `.zip` archive containing the requested provider plugin version.
   227  
   228    Terraform resolves the URL relative to the URL from which the current
   229    JSON document was returned, so the examples above containing only a
   230    filename would cause Terraform to construct a URL like:
   231  
   232    ```
   233    https://terraform.example.com/providers/registry.terraform.io/hashicorp/random/terraform-provider-random_2.0.0_darwin_amd64.zip
   234    ```
   235  
   236  * `hashes` (optional): a JSON array of strings containing one or more hash
   237    values for the indicated archive. These hashes use Terraform's provider
   238    package hashing algorithm. At present, the easiest way to populate these
   239    is to construct a mirror's JSON indices using the `terraform providers mirror`
   240    command, as described in a later section, which will include the calculated
   241    hashes of each provider.
   242  
   243    If the response includes at least one hash, Terraform will select the hash
   244    whose algorithm it considers to be strongest and verify that the downloaded
   245    package matches that hash. If the response does not include a `hashes`
   246    property then Terraform will install the indicated archive with no
   247    verification.
   248  
   249  Terraform CLI will only attempt to download versions that it has previously
   250  seen in response to [List Available Versions](#list-available-versions).
   251  
   252  ## Provider Mirror as a Static Website
   253  
   254  The provider mirror protocol is designed so that it can potentially be implemented
   255  by placing files on typical static website hosting services. When using this
   256  strategy, implement the JSON index responses described above as `.json` files
   257  in the appropriate nested subdirectories, and ensure that your system is
   258  configured to serve `.json` files with the `application/json` media type.
   259  
   260  As a convenience, Terraform CLI includes
   261  [the `terraform providers mirror` subcommand](/cli/commands/providers/mirror),
   262  which will analyze the current configuration for the providers it requires,
   263  download the packages for those providers from their origin registries, and
   264  place them into a local directory suitable for use as a mirror.
   265  
   266  The `terraform providers mirror` subcommand also generates `index.json` and
   267  version-specific `.json` files that can, when placed in a static website hosting
   268  system, produce responses compatible with the provider mirror protocol.
   269  
   270  If you wish to create a mirror with providers for a number of different
   271  Terraform configurations, run `terraform providers mirror` in each configuration
   272  in turn while providing the same output directory each time. Terraform will
   273  then merge together all of the requirements into a single set of JSON indices.