1

I have the exact same problem as here Terraform tries to load old defunct provider and the solution posted there does not work for me.

Problem is that i define in the terraform config:

required_providers {
    postgresql = {
        source  = "cyrilgdn/postgresql"
        version = ">=1.13.0"
    }
}

But the terraform init process always tries to download hashicorp/postgresql and can not find it in the end.

My current terraform version is:

Terraform v1.0.6 on windows_amd64

I did try a lot and played around with the resource parameter "provider" to explicitly set the provider for all resources but even with that i did not find a way.

Can anybody help here again or post me a working example for this provider?

Marius
  • 11
  • 3
  • 1
    The `required_providers` is correct and works as expected. You can check in new folder with new main.tf. – Marcin Sep 15 '21 at 10:33
  • 1
    You can run the command `terraform providers` to see all of the providers Terraform can see references to in your current configuration. The most common cause of the problem you've seen here are not declaring the required providers in your child modules too, in which case `terraform providers` will show you which module the `hashicorp/postgresql` dependency is coming from. – Martin Atkins Sep 15 '21 at 18:05

2 Answers2

1

So, for us the solution is - because we are using submodules and every Submodule/Re-usable that uses postgresql providers require this provider-config within.

Ex: lets say you have below terraform code structure,

.
├── versions.tf
├── outputs.tf
├── main.tf
├── modules
│   ├── postgres
│   │   ├── outputs.tf
│   │   ├── db.tf
│   │   └── variable.tf

I had to define "required_providers" both in versions.tf and db.tf files, like below

terraform {
  required_providers {
    postgresql = {
      source  = "cyrilgdn/postgresql"
    }
  }

  required_version = ">= 1.0.0"
}

Hope this helps ! All the best

Harry
  • 21
  • 2
0

I got the solution! The problem what i had was my folder structure. I had a specific folder structure like:

environments like dev/int/prod and i had a config.tf in there with the required providers.

resources where i use the resources i want to add and what i missed there is the a copy of the config.tf file.

So this means i need a config.tf file in every subfolder which consists modules.

Marius
  • 11
  • 3