How to instruct module to use particular provider in terraform?


I want to create a module that is linked to my artifactory provider. In my where I have configured my providers, I also have hashicorp/aws defined like below…

terraform {
  required_version = "~> 1.2.4"
  required_providers {
    aws = {
      version = "4.64.0"
      source  = "hashicorp/aws"
    artifactory = {
      version = "6.22.3"
      source  = ""
provider "artifactory" {
  url           = "<my artifactory url>"
  access_token  = "<my token>"
// AWS // 
provider "aws" {
  region              = var.region
  allowed_account_ids = [var.account_id]
  assume_role {
    role_arn = var.terraform_role_arn

When I attempt to create a module using artifactory provider like the below inside a file….

module "artifactory_resources" {
  source     = "./modules/artifactory_resources"
  provider = artifactory
module "model_store_s3" {
  source     = "./modules/storage/s3"
  aws_region = local.aws_region

I get the following error…

Could not retrieve the list of available versions for provider hashicorp/artifactory: provider registry does not have a provider named

Did you intend to use jfrog/artifactory? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on hashicorp/artifactory, run the following command: terraform providers

And when I run terraform providers I can see my module is trying to use a non-existent provider…

Providers required by configuration:
├── provider[] 6.22.3
├── provider[] 4.64.0
├── module.model_store_s3
│   └── provider[]
├── module.artifactory_resources
│   ├── provider[]
│   └── provider[]

I can see the wrong provider is being used in the module, how can I change providers fromprovider[ to

>Solution :

Each module has to have required providers defined as per the documentation:

Each Terraform module must declare which providers it requires, so that Terraform can install and use them. Provider requirements are declared in a required_providers block.

Furthermore, there is one really important thing to note:

Each module must declare its own provider requirements. This is especially important for non-HashiCorp providers.

This means you have to declare the Artifactory provider (as it is a non-HashiCorp provider) inside of the module code, i.e., in the artifactory_resources module. The way provider configuration is inherited is detailed in the documentation as well.

Leave a ReplyCancel reply