terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt assumes hasicorp/<provider> when generated provider block is used

Open ch9hn opened this issue 2 years ago • 8 comments

Hello, we faced some issues with the generated provider blocks from Terragrunt.

In our module we have a file called "versions.tf":

terraform {
  required_version = ">= 1.4"
  required_providers {
    scaleway = {
      source  = "scaleway/scaleway"
      version = ">= 2.16"
    }
  }

}

When we add a provider block in the base terragrunt.hcl:

#Generate a SCW Provider Block
generate "provider" {
  path      = "provider.tf"
  if_exists = "overwrite"
  contents  = <<-EOF
    provider "scaleway" {
      region          = var.region
      zone            = var.zone
      organization_id = var.organization_id
}

variable "region" {
  description = "SCW Region."
}
variable "zone" {
  description = "SCW Zone."
}

variable "organization_id" {
  description = "SCW Orga ID"
}

  EOF
}

We get the following errors - also with other providers which are not from hashicorp because the merging of the files is not consistent


│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider
│ hashicorp/scaleway: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/scaleway
│ 
│ Did you intend to use scaleway/scaleway? If so, you must specify that
│ source address in each module which requires that provider. To see which
│ modules are currently depending on hashicorp/scaleway, run the following
│ command:
│     terraform providers
╵

The only solution is, to replicate the provider configuration into every module.

Does someone have similar issues ?

ch9hn avatar Apr 14 '23 20:04 ch9hn

Are you referencing the module in a root module where also the base terragrunt lives?

juljaeg avatar Apr 19 '23 10:04 juljaeg

Hi, I'm experiencing the same issue with the Doppler provider. Looks like it's trying to install from hashicorp instead of 3rd party registry.

We have the following structure (this is for testing):

terragrunt.hcl

remote_state {
  backend = "local"
  config = {
    path = "${get_parent_terragrunt_dir()}/${path_relative_to_include()}/terraform.tfstate"
  }

  generate = {
    path      = "versions.tf"
    if_exists = "overwrite_terragrunt"
    contents  = <<-EOF
      required_providers {
        doppler = {
          source = "DopplerHQ/doppler"
          version = "1.3.0"
        }
    EOF
  }
}

generate "provider" {
  path      = "provider.tf"
  if_exists = "overwrite"
  contents  = <<-EOF
    provider "doppler" {
      doppler_token = "<token>"
    }
  EOF
}

Running terragrunt init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/doppler...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/doppler: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/doppler
│
│ All modules should specify their required_providers so that external
│ consumers will get the correct providers when using a module. To see which
│ modules are currently depending on hashicorp/doppler, run the following
│ command:
│     terraform providers
╵

ERRO[0000] Terraform invocation failed in /home/user/repos/GitHub/doppler
ERRO[0000] 1 error occurred:
        * [/home/user/repos/GitHub/doppler] exit status 1

xPiSeaZx avatar Sep 18 '23 03:09 xPiSeaZx

Same here with a gitlab provider:

generate "provider" {
  path      = "providers.tf"
  if_exists = "overwrite_terragrunt"
  contents  = <<EOF
provider "gitlab" {
  token    = var.GITLAB_TOKEN
  base_url = var.BASE_URL
}
EOF
}

versions.tf in a module:

terraform {
  required_version = ">= 1.6.4"

  required_providers {
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = ">= 2.23.0"
    }
    gitlab = {
      source  = "gitlabhq/gitlab"
      version = ">= 16.6.0"
    }
  }
}

output:


Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/kubernetes...
- Finding latest version of hashicorp/gitlab...
- Installing hashicorp/kubernetes v2.23.0...
- Installed hashicorp/kubernetes v2.23.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider
│ hashicorp/gitlab: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/gitlab
│ 
│ Did you intend to use gitlabhq/gitlab? If so, you must specify that source
│ address in each module which requires that provider. To see which modules
│ are currently depending on hashicorp/gitlab, run the following command:
│     terraform providers

AsoTora avatar Nov 24 '23 04:11 AsoTora

You need to add gitlab as a required provider in the root module as well, not just in the module.

juljaeg avatar Nov 24 '23 20:11 juljaeg

Same problem here; the main driver of my problems is that my root module might have providers that are true for most of the cases e.g aws/random providers, however on my child-modules I would like to be able to override them in case I wanna use different versions of the providers.

Doing something like:

root Terragrunt:

generate "versions" {
  path      = "versions.tf"
  if_exists = "overwrite_terragrunt"
  contents  = <<EOF
terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "5.46.0"
    }
    random = {
      source = "hashicorp/random"
      version = "3.5.1"
    }
  }
}
EOF
}

Child module; same providers as parent config but adding an extra configuration for my extra child provider.

generate "versions_overwrite" {
  path      = "versions.tf"
  if_exists = "overwrite"
  contents  = <<EOF
  terraform {
    required_providers {
      aws = {
        source = "hashicorp/aws"
        version = "~> 5.46.0"
      }
      random = {
        source = "hashicorp/random"
        version = "~> 3.5.1"
      }
      dnsimple = {
        source  = "dnsimple/dnsimple"
        version = "~> 1.6.0"
      }
    }
  }
EOF
}

This gives problems like e.g

git:(main) ✗ terragrunt plan

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/random from the dependency lock file
- Finding latest version of hashicorp/dnsimple...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hashicorp/random v3.5.1
- Using previously-installed hashicorp/aws v5.46.0
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/dnsimple: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/dnsimple
│
│ Did you intend to use dnsimple/dnsimple? If so, you must specify that
│ source address in each module which requires that provider. To see which
│ modules are currently depending on hashicorp/dnsimple, run the following
│ command:
│     terraform providers

ShankyJS avatar Jul 09 '24 06:07 ShankyJS

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for raising this issue.

github-actions[bot] avatar Nov 12 '24 02:11 github-actions[bot]

Same problem.

mcujba avatar Nov 12 '24 18:11 mcujba

Has anyone found a solution or work around to this yet? I am running into the same issue.

joshuayoerger avatar Dec 06 '24 22:12 joshuayoerger

Same problem here. I'd like to use GoDaddy to configure DNS records for my domain. Terragrant wants to use hashicorp/goddaddy...

Paccelerator2 avatar Dec 24 '24 04:12 Paccelerator2

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for raising this issue.

github-actions[bot] avatar Mar 25 '25 02:03 github-actions[bot]

Same problem

toanho912 avatar Aug 25 '25 23:08 toanho912