TFNFR27 - Provider Declarations in Modules

ID: TFNFR27 - Category: Code Style - Provider Declarations in Modules

By rule, every published AVM module and submodule MUST NOT declare a provider block. Provider configuration belongs exclusively to the consuming root module.

When a module requires an alternate provider instance, it MUST declare that alias through configuration_aliases in terraform.required_providers and the consumer MUST pass the configured alias through the module’s providers map. A provider block containing only alias is not permitted in an AVM module.

This is enforced by terraform_module_provider_declaration.

Good examples:

In verified module:

terraform {
  required_providers {
    azapi = {
      source                = "Azure/azapi"
      version               = "~> 2.12"
      configuration_aliases = [azapi.alternate]
    }
  }
}

In the root module where we call this verified module:

provider "azapi" {}

provider "azapi" {
  alias = "alternate"
}

module "foo" {
  source = "xxx"
  providers = {
    azapi           = azapi
    azapi.alternate = azapi.alternate
  }
}

Bad example:

In verified module:

provider "azapi" {
  alias = "alternate"
}