Description
Describe the bug
When a resource, datasource or module's provider uses a variable as the key to the a provider generated with a for_each
statement the following error is returned:
> terraform-docs markdown document .
Error: Invalid provider reference: Provider argument requires a provider name followed by an optional alias, like "aws.foo".
How can we reproduce it?
Use a for_each statement to generate a provider, then reference the provider using something dynamic, such as a variable, local, etc.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
locals {
provider_names = ["foo"]
}
provider "aws" {
for_each = toset(local.provider_names)
alias = "my_aws_providers"
}
data "aws_caller_identity" "current" {
provider = aws.my_aws_providers[local.provider_names[0]]
}
Environment information
Terraform Docs version:
> terraform-docs --version
OpenTofu v1.9.0
on darwin_arm64
+ provider registry.opentofu.org/hashicorp/aws v5.89.0
OS: MacOS Sonoma 14.7 on Apple M3 Pro