Blocks with multiple providers
A module may need more than one provider configuration, for example two regions or two different providers. A template can declare one provider field for each. Each field binds a configured provider to a provider name inside the module, and optionally to an alias.
Example: two configurations of one provider type
This example uses the random provider, which needs no credentials. Create a provider type random with source
hashicorp/random and version 3.6.3. Wait for its schema synchronization job to finish, then create two providers,
random-east and random-west, with empty configuration objects.
Store modules/dual_names/main.tf:
terraform {
required_providers {
random = {
source = "hashicorp/random"
version = "3.6.3"
configuration_aliases = [random.east, random.west]
}
}
}
variable "prefix" {
type = string
}
resource "random_pet" "east" {
provider = random.east
prefix = var.prefix
length = 2
}
resource "random_pet" "west" {
provider = random.west
prefix = var.prefix
length = 2
}
output "names" {
value = { east = random_pet.east.id, west = random_pet.west.id }
}The module declares the aliases in configuration_aliases, but it does not declare the configured providers.
InfraBuffet supplies those from the infrastructure’s providers.
Create a template for that module. In Form fields, add three required fields:
prefix: choose String.east_provider: choose Provider, selectrandomfrom Provider type, and entereastin Provider alias.west_provider: choose Provider, selectrandomfrom Provider type, and enterwestin Provider alias.
The equivalent field definitions are shown below as YAML for reference. Numbers such as provider_type: 10 are IDs;
in the UI, select the provider type from the dropdown.
- name: prefix
type: string
mode: required
- name: east_provider
type: provider
mode: required
provider_type: 10
provider_alias: east
- name: west_provider
type: provider
mode: required
provider_type: 10
provider_alias: westCreate a block from this template. Enter demo for prefix, then choose random-east for east_provider and
random-west for west_provider from their dropdowns.
The equivalent values are shown below as YAML for reference. 41 and 42 are provider IDs; the UI records them
when you choose the providers.
prefix: demo
east_provider: 41
west_provider: 42prefix reaches the module as a normal input. The providers become this mapping:
providers = {
random.east = random.random-east
random.west = random.random-west
}The left side is the module’s alias. The right side is the configured provider in InfraBuffet. The form keys
east_provider and west_provider are not module variables.
Rules
- For each provider field, select a Provider type. Set Provider alias only when the module declares an aliased provider. For an unaliased provider, leave it empty.
- The provider name the module uses must match the provider type’s name, such as
aws. The module’s source and version must be compatible with the provider type’s version. - InfraBuffet checks that the selected provider exists in the same infrastructure and matches the field’s Provider type.
- An empty optional provider field adds no binding. Make a field required if the module needs that binding.
- Once a block has any provider binding, InfraBuffet stops adding the scope’s default provider to it. Bind every provider the module needs, including an unaliased one.