Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Previewing the upcoming module provider configurations in TF 0.11

Note: This is a preview for TF 0.11. You should reference the official Terraform docs for up to date information.

Before (Terraform <= 0.10.x)

Modules can only inherit provider configurations, and modules inheritance around aliased providers is unclear.

Use case: if you want two have two modules where you want one two create resources in the us-west region and the other to create resources in the us-east region. In Terraform <= 0.10.x, this is not possible.

Bugs: Besides the above, numerous bugs around provider inheritence edge cases remained. For example: if you create an aliased provider in the root, and have a module which itself has a module, that grandchild module would not inherit the root aliased provider. Or, even if it did this was sometimes unexpected for users. So in both cases we've had "bugs" reported!

After (Terraform >= 0.11.0)

Modules only automatically inherit non-aliased providers. For example: if you configure the aws provider in the root and a module uses AWS resources, then the module will use that configuration.

For aliased providers, you can now explicit target a certain provider configuration. And aliased provider configuration is never automatically inherited.

Modules now have a providers block which is a mapping of providers to their named configurations that the module should use. The key in the mapping is the name of the provider in the module and the value is the name of the configuration in the current configuration that the module should use. Example:

module "consul" {
  source = "hashicorp/consul/aws"
  
  providers = {
    "aws"      = "aws.west" // override defaults!
    "aws.east" = "aws.east" // specify an alias
  }
}

provider "aws" {
  alias = "west"
  //...
}

provider "aws" {
  alias = "east"
  //...
}

This tells the "consul" module to use the "aws.west" configuration for the "aws" (unaliased) provider, and "aws.east" for the "aws.east" provider within the module.

Explicit is better than implicit! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment