Terraform 1.1.X: Using libvirt in child module

I am trying to use libvirt in my child module, but I get an error.
Code:

terraform {
required_version = ">= 1.1.6"
required_providers {
  libvirt = {
    source  = "dmacvicar/libvirt"
    version = ">= 0.6.14"
  }
}
}

provider "libvirt" {
uri   = "qemu:///system"
alias = "local"
}
module "my_local_kvm_module" {

source = "../modules/KVM/kvm_vm"
providers = {
  libvirt = libvirt.local
}
some_vars="some_vals"
}

Error is quite strange:

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Warning: Provider libvirt is undefined
│ 
│   on main.tf line 19, in module "my_local_kvm_module":
│   19:     libvirt = libvirt.local
│ 
│ Module module.my_local_kvm_module does not declare a provider named libvirt.
│ If you wish to specify a provider configuration for the module, add an entry for libvirt in the
│ required_providers block within the module.
╵

╷
│ Error: Invalid type for provider module.my_local_kvm_module.provider["registry.terraform.io/hashicorp/libvirt"]
│ 
│   on main.tf line 19, in module "my_local_kvm_module":
│   19:     libvirt = libvirt.local
│ 
│ Cannot use configuration from provider["registry.terraform.io/dmacvicar/libvirt"].local for
│ module.my_local_kvm_module.provider["registry.terraform.io/hashicorp/libvirt"]. The given
│ provider configuration is for a different provider type.

Looks like provider can’t be found inside module, the same code works with just resource sections instead of module.

Could You tell me how it should be configured ??

Thanks for Your help.

Best regards,
Dawid

Hi @dawid.dacewicz.utm,

You will also need to include the required_providers block in the child module, because that’s how Terraform knows that “libvirt” in that module means dmacvicar/libvirt, rather than hashicorp/libvirt (which doesn’t exist).