Skip to content

Commit 76dd363

Browse files
committed
Add documentation for provider_meta.
1 parent 82088c9 commit 76dd363

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

website/docs/configuration/terraform.html.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,11 @@ Re-usable modules should constrain only the minimum allowed version, such
121121
as `>= 1.0.0`. This specifies the earliest version that the module is
122122
compatible with while leaving the user of the module flexibility to upgrade
123123
to newer versions of the provider without altering the module.
124+
125+
## Passing Metadata to Providers
126+
127+
The `terraform` block can have a nested `provider_meta` block for each
128+
provider a module is using, if the provider defines a schema for it. This
129+
allows the provider to receive module-specific information. No interpolations
130+
are performed on this block. For more information, see the
131+
[`provider_meta` page](/docs/internals/provider-meta.html).
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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.

website/layouts/docs.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@
450450
<li<%= sidebar_current("docs-internals-plugins") %>>
451451
<a href="/docs/internals/internal-plugins.html">Internal Plugins</a>
452452
</li>
453+
454+
<li<%= sidebar_current("docs-internals-provider-meta") %>>
455+
<a href="/docs/internals/provider-meta.html">Provider Metadata</a>
456+
</li>
453457
</ul>
454458
</li>
455459

0 commit comments

Comments
 (0)