Skip to content

Commit 8f914ae

Browse files
committed
draft of providers m-a ref
1 parent 8091319 commit 8f914ae

File tree

5 files changed

+153
-80
lines changed

5 files changed

+153
-80
lines changed

content/terraform/v1.13.x/data/language-nav-data.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,17 @@
373373
"title": "for_each",
374374
"path": "meta-arguments/for_each"
375375
},
376+
{
377+
"title": "lifecycle",
378+
"path": "meta-arguments/lifecycle"
379+
},
376380
{
377381
"title": "provider",
378382
"path": "meta-arguments/provider"
383+
},
384+
{
385+
"title": "providers",
386+
"path": "meta-arguments/providers"
379387
}
380388
]
381389
},

content/terraform/v1.13.x/docs/language/block/module.mdx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -453,18 +453,7 @@ module "<LABEL>" {
453453
}
454454
```
455455

456-
By default, a child module inherits the default provider configuration from its parent module, but you can create multiple provider configurations and use an alternate configuration for each module. Because a module is collection of different resources, some modules also let you specify an alternate configuration for different resources in the module. Refer to the module documentation for details.
457-
458-
The `providers` argument is a map of key-value pairs that reference provider configurations. The key references the provider configuration name used in the child module. Refer to the module documentation for details on how to define keys. The value references the provider configuration name from the parent module. Use the `<PROVIDER>.<ALIAS>` syntax to reference alternate provider configurations in key values.
459-
460-
The `providers` argument is a meta-argument, which is built into Terraform and controls the way that Terraform creates resources. Refer to [Meta-arguments](/terraform/language/meta-arguments) for more information.
461-
462-
#### Summary
463-
464-
- Data type: Map.
465-
- Default: None.
466-
- Example: [Apply different provider configurations for module resources](#apply-different-provider-configurations-for-module-resource)
467-
456+
`providers` is a **meta-argument**. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the [`providers` reference](/terraform/language/meta-arguments/providers) for details about how the argument works.
468457

469458
### `depends_on`
470459

@@ -731,26 +720,3 @@ module "vpc" {
731720
}
732721
```
733722

734-
### Apply different provider configurations for module resources
735-
736-
In the following example, the `tunnel` module includes resources that support their own provider configuration. As a result, each resource alias maps to a different provider configurations declared in the root module:
737-
738-
```hcl
739-
provider "aws" {
740-
alias = "usw1"
741-
region = "us-west-1"
742-
}
743-
744-
provider "aws" {
745-
alias = "usw2"
746-
region = "us-west-2"
747-
}
748-
749-
module "tunnel" {
750-
source = "./tunnel"
751-
providers = {
752-
aws.src = aws.usw1
753-
aws.dst = aws.usw2
754-
}
755-
}
756-
```

content/terraform/v1.13.x/docs/language/meta-arguments/index.mdx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,7 @@ By default, Terraform determines the local name of the provider from the first w
4040

4141
## `providers`
4242

43-
By default, child modules inherit the default provider configurations of their parent module. You can specify an alternate provider configuration in the `module` block using the `providers` argument. The `providers` argument instructs Terraform to use the reference provider configuration to create the module resources.
44-
45-
Some modules may contain resources that require different providers. As a result, you can specify alternate configurations for each provider supported by the module. Refer to the module documentation for details about the providers it supports.
46-
47-
When you add a `providers` argument, child modules only have access to the provider configurations you specify. Use the `providers` argument in the following scenarios:
48-
49-
- To use an alternate provider configuration for a child module.
50-
- To configure a module that requires multiple configurations of the same provider.
51-
52-
### Examples
53-
54-
- [Apply different provider configurations](/terraform/language/block/module#apply-different-provider-configurations-for-module-resources) for module resources
55-
56-
### Guidance
57-
58-
- [Provider Aliases Within Modules](/terraform/language/modules/develop/providers#provider-aliases-within-modules)
59-
60-
### Reference
61-
62-
- [`providers` argument in `module` blocks](/terraform/language/block/module#providers)
63-
- [Providers module development documentation](/terraform/language/modules/develop/providers)
43+
By default, child modules inherit the default provider configurations of their parent module. You can specify an alternate provider configuration in the `module` block using the `providers` argument. The `providers` argument instructs Terraform to use the reference provider configuration to create the module resources. Refer to the [`providers` reference](/terraform/language/meta-arguments/providers) for details.
6444

6545
## `lifecycle`
6646

content/terraform/v1.13.x/docs/language/meta-arguments/provider.mdx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,28 +114,4 @@ import {
114114
resource "aws_instance" "web" {
115115
# ...
116116
}
117-
```
118-
119-
### Apply different provider configurations for module resources
120-
121-
In the following example, the `tunnel` module includes resources that support their own provider configuration. As a result, each resource alias maps to a different provider configurations declared in the root module:
122-
123-
```hcl
124-
provider "aws" {
125-
alias = "usw1"
126-
region = "us-west-1"
127-
}
128-
129-
provider "aws" {
130-
alias = "usw2"
131-
region = "us-west-2"
132-
}
133-
134-
module "tunnel" {
135-
source = "./tunnel"
136-
providers = {
137-
aws.src = aws.usw1
138-
aws.dst = aws.usw2
139-
}
140-
}
141117
```
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
page_title: providers meta-argument reference
3+
description: Learn how the `providers` meta-argument works in Terraform configuration.
4+
---
5+
6+
# `providers` reference
7+
8+
By default, child modules inherit the default provider configurations of their parent module. You can specify an alternate provider configuration in the `module` block using the `providers` argument. The `providers` argument instructs Terraform to use the reference provider configuration to create the module resources.
9+
10+
## Usage
11+
12+
In a [`module` block](/terraform/language/module/syntax), you can add the optional `providers` meta-argument to specify which [provider configurations](/terraform/language/modules/configuration) from the parent module is available inside the child module.
13+
14+
The value of `providers` is a map, where the keys are the provider configuration names used inside the child module and the values are provider configuration names from the parent module.
15+
16+
Keys and values are unquoted references to provider configurations.
17+
For default configurations, the reference is the local name of the provider. For
18+
alternate configurations, the reference uses a `<PROVIDER>.<ALIAS>` format.
19+
20+
Within a child module, either Terraform chooses a default based on the name of the resource
21+
type, or the resource specifies an alternate configuration with the `provider`
22+
argument. If the module receives a `providers` map when it's called, the
23+
provider configuration names used within the module are effectively remapped to
24+
refer the specified configurations from the parent module.
25+
26+
In the following example, Terraform uses the default `aws` configuration for AWS resources in the root module where no explicit provider instance is selected, but the example child moduleuses the alternate configuration with the alias `usw2`. As a result, any AWS resources the module defines uses the `us-west-2` region.
27+
28+
29+
```hcl
30+
provider "aws" {
31+
region = "us-west-1"
32+
}
33+
34+
provider "aws" {
35+
alias = "usw2"
36+
region = "us-west-2"
37+
}
38+
39+
module "example" {
40+
source = "./example"
41+
providers = {
42+
aws = aws.usw2
43+
}
44+
}
45+
```
46+
47+
### Default behavior
48+
49+
The `providers` argument is optional when the child module does not declare a [`configuration_aliases`](/terraform/language/modules/develop/providers#provider-aliases-within-modules). When you omit the argument, a child module inherits all of the default provider configurations from its parent module. Default provider configurations are configurations that don't have an `alias` argument.
50+
51+
Specifying a `providers` argument cancels the default behavior. As a result, the child module only has access to the provider configurations you specify.
52+
53+
54+
### When to specify `providers`
55+
56+
Add the `providers` argument when one of the following conditions apply:
57+
58+
- Using different default provider configurations for a child module.
59+
- Configuring a module that requires multiple configurations of the same provider.
60+
61+
### Change default provider configurations
62+
63+
Most re-usable modules only use default provider configurations, which they can
64+
automatically inherit from their caller when `providers` is omitted.
65+
66+
However, in Terraform configurations that use multiple configurations of the same provider, you might want some child modules to use the default provider configuration and others to use an alternate.
67+
A common use case is using one configuration to manage resources in multiple different regions of the same cloud provider.
68+
69+
Using `providers` argument lets you accommodate this without needing to edit the child module. Although the code
70+
within the child module always refers to the default provider configuration, the
71+
actual configuration of that default can be different for each instance.
72+
73+
74+
## Information for module developers
75+
76+
For more details and guidance about working with providers inside a re-usable
77+
child module, refer to [Providers Within Modules](/terraform/language/modules/develop/providers).
78+
79+
## Supported constructs
80+
81+
You can use `providers` in the following Terraform configuration blocks:
82+
83+
- [`module` blocks](/terraform/language/block/module)
84+
85+
### Example use cases
86+
87+
The following use cases describe common patterns for the `providers` argument.
88+
89+
### Apply different provider configurations for module resources
90+
91+
In the following example, the `tunnel` module includes resources that support their own provider configuration. As a result, each resource alias maps to a different provider configurations declared in the root module:
92+
93+
```hcl
94+
provider "aws" {
95+
alias = "usw1"
96+
region = "us-west-1"
97+
}
98+
99+
provider "aws" {
100+
alias = "usw2"
101+
region = "us-west-2"
102+
}
103+
104+
module "tunnel" {
105+
source = "./tunnel"
106+
providers = {
107+
aws.src = aws.usw1
108+
aws.dst = aws.usw2
109+
}
110+
}
111+
```
112+
113+
### Modules with alternate provider configurations
114+
115+
In rare cases, a single re-usable module might require multiple configurations
116+
of the same provider. For example, a module that configures connectivity between
117+
networks in two AWS regions is likely to need both a `source` and a `destination`
118+
region. The following example shows possible root module configuration for this use case:
119+
120+
```hcl
121+
provider "aws" {
122+
alias = "usw1"
123+
region = "us-west-1"
124+
}
125+
126+
provider "aws" {
127+
alias = "usw2"
128+
region = "us-west-2"
129+
}
130+
131+
module "tunnel" {
132+
source = "./tunnel"
133+
providers = {
134+
aws.src = aws.usw1
135+
aws.dst = aws.usw2
136+
}
137+
}
138+
```
139+
140+
Non-default provider configurations are never automatically inherited, so any
141+
module that works in this manner always requires a `providers` argument. The
142+
documentation for the module should specify all of the provider configuration
143+
names it needs.

0 commit comments

Comments
 (0)