Add docs for provider limitations when expanding modules (#25007)

* Add docs for provider limitations when expanding modules
This commit is contained in:
Pam Selle 2020-05-21 14:04:44 -04:00 committed by GitHub
parent 5c49710893
commit bfbdb4cb1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 3 deletions

View File

@ -350,6 +350,8 @@ provider "aws" {
Each resource should then have its own `provider` attribute set to either
`"aws.src"` or `"aws.dst"` to choose which of the two provider instances to use.
### Proxy Configuration Blocks
A proxy configuration block is one that is either completely empty or that
contains only the `alias` argument. It serves as a placeholder for
provider configurations passed between modules. Although an empty proxy
@ -423,10 +425,53 @@ deleted.
### Limitations when using module expansion
Modules using `count` or `for_each` cannot pass different sets of providers to different instances.
Modules using `count` or `for_each` cannot include configured `provider` blocks within the module.
Only [proxy configuration blocks](#proxy-configuration-blocks) are allowed.
If a module contains proxy configuration blocks, the calling module block must be have the
corresponding providers passed to the `providers` argument. If you attempt to use `count` or
`for_each` with a module that does not satify this requirement, you will see an error:
```
Error: Module does not support count
on main.tf line 15, in module "child":
15: count = 2
Module "child" cannot be used with count because it contains a nested provider
configuration for "aws", at child/main.tf:2,10-15.
This module can be made compatible with count by changing it to receive all of
its provider configurations from the calling module, by using the "providers"
argument in the calling module block.
```
Assuming the child module only has proxy configuration blocks, the calling
module block could be adjusted like so to remove this error:
```
provider "aws" {
region = "us-east-1"
alias = "east"
}
module "child" {
count = 2
providers = {
aws = aws.east
}
}
```
Note how we are now [passing the providers](#passing-providers-explicitly) to the child module.
In addition, modules using `count` or `for_each` cannot pass different sets of providers
to different instances. For example, you cannot interpolate variables in the `providers`
block on a module.
This is because when a module instance is destroyed (such as a key-value being removed from the
`for_each` map), the provider must be available in order to perform the destroy. You can pass
different sets of providers by using multiple `module` blocks:
`for_each` map), the appropriate provider must be available in order to perform the destroy.
You can pass different sets of providers to different module instances by using multiple `module` blocks:
```
# my_buckets.tf