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