github.com/hugorut/terraform@v1.1.3/website/docs/internals/provider-meta.mdx (about)

     1  ---
     2  page_title: Provider Metadata
     3  description: >-
     4    For advanced use cases, modules can provide some pre-defined metadata for
     5    providers.
     6  ---
     7  
     8  # Provider Metadata
     9  
    10  In some situations it's beneficial for a provider to offer an interface
    11  through which modules can pass it information unrelated to the resources
    12  in the module, but scoped on a per-module basis.
    13  
    14  Provider Metadata allows a provider to declare metadata fields it expects,
    15  which individual modules can then populate independently of any provider
    16  configuration. While provider configurations are often shared between modules,
    17  provider metadata is always module-specific.
    18  
    19  Provider Metadata is intended primarily for the situation where an official
    20  module is developed by the same vendor that produced the provider it is
    21  intended to work with, to allow the vendor to indirectly obtain usage
    22  statistics for each module via the provider. For that reason, this
    23  documentation is presented from the perspective of the provider developer
    24  rather than the module developer.
    25  
    26  ~> **Advanced Topic!** This page covers technical details
    27  of Terraform. You don't need to understand these details to
    28  effectively use Terraform. The details are documented here for
    29  module authors and provider developers working on advanced
    30  functionality.
    31  
    32  ~> **Experimental Feature!** This functionality is still considered
    33  experimental, and anyone taking advantage of it should [coordinate
    34  with the Terraform team](https://github.com/hugorut/terraform/issues/new)
    35  to help the team understand how the feature is being used and to make
    36  sure their use case is taken into account as the feature develops.
    37  
    38  ## Defining the Schema
    39  
    40  Before a provider can receive information from a module, the provider
    41  must strictly define the data it can accept. You can do this by setting
    42  the `ProviderMeta` property on your `schema.Provider` struct. Its value
    43  functions similarly to the provider config: a map of strings to the
    44  `schema.Schema` describing the values those strings accept.
    45  
    46  ## Using the Data
    47  
    48  When Terraform calls your provider, you can use the `schema.ResourceData`
    49  that your `Create`, `Read`, and `Update` functions already use to get
    50  access to the provider metadata being passed. First define a struct
    51  that matches your schema, then call the `GetProviderSchema` method on
    52  your `schema.ResourceData`, passing a pointer to a variable of that type.
    53  The variable will be populated with the provider metadata, and will return
    54  an error if there was an issue with parsing the data into the struct.
    55  
    56  ## Specifying Data in Modules
    57  
    58  To include data in your modules, create a `provider_meta` nested block under
    59  your module's `terraform` block, with the name of the provider it's trying
    60  to pass information to:
    61  
    62  ```hcl
    63  terraform {
    64    provider_meta "my-provider" {
    65      hello = "world"
    66    }
    67  }
    68  ```
    69  
    70  The `provider_meta` block must match the schema the provider has defined.
    71  
    72  ## Versioning Your Modules
    73  
    74  Any module taking advantage of this functionality must make sure that the
    75  provider metadata supplied matches the schema defined in the provider, and
    76  that the version of Terraform that is being run has support for the provider
    77  metadata functionality. It's therefore recommended that any module taking
    78  advantage of this functionality should specify a minimum Terraform version of
    79  0.13.0 or higher, and a minimum version of each of the providers it specifies
    80  metadata as the first version the schema being used was supported by the
    81  provider.