3
votes

I'm confused on how to properly specify the postgres provider for v0.13.4 of terraform.

Note: originally this provider doc was fine for v12 to get everything working: https://www.terraform.io/docs/providers/postgresql/index.html

and on v0.12 when running terraform providers I'll get something similar to this:

.
├── provider.aws
└── <some module>
    ├── provider.aws
    ├── provider.postgresql
    ├── provider.template
    ├── provider.terraform

I can also check the plugin bin and see what version of the plugin was downloaded and it's hash. With version 0.13.x we need to now specify providers with the new schema. Looking here I can see 2 community postgresql providers.. which makes me confused on how one was being specified over the other originally. https://registry.terraform.io/browse/providers?category=database

It seems like I was using this provider?: https://registry.terraform.io/providers/cyrilgdn/postgresql/latest

When I run terraform init (after --reconfigure) on v0.13.4 my error message contains:

Initializing provider plugins...
- terraform.io/builtin/terraform is built in to Terraform
- Using previously-installed hashicorp/template v2.2.0
- Using previously-installed hashicorp/aws v3.11.0
- Using previously-installed terraform-providers/postgresql v1.7.1
- Finding latest version of hashicorp/postgresql...

Error: Failed to install providers

Could not find required providers, but found possible alternatives:

  hashicorp/postgresql -> terraform-providers/postgresql

If these suggestions look correct, upgrade your configuration with the
following command:

The following remote modules must also be upgraded for Terraform 0.13
compatibility:
- module.<some value> at
git::git@git<some value>

Questions:

How does it specify one postgres community provider over another? (at least originally)

Why is it trying to reference hashicorp/posgresql.

Why is it telling me to use terraform-providers/postgresql instead of something like the source provider of cyrilgdn/terraform-provider-postgresql ?

Last question, even after adding:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
    }
    postgresql = {
      source  = "terraform-providers/postgresql"
    }
  }

  required_version = ">= 0.13"
}

terraform providers output

├── provider[registry.terraform.io/hashicorp/aws]
└── <some module.repo>
    ├── provider[registry.terraform.io/hashicorp/aws]
    ├── provider[registry.terraform.io/terraform-providers/postgresql]
    ├── provider[registry.terraform.io/hashicorp/postgresql]
    ├── provider[terraform.io/builtin/terraform]
    ├── provider[registry.terraform.io/hashicorp/template]

It does add the new provider but doesn't remove the seemingly unneeded hashicorp/postgresql which still results in the same error message. Can someone explain how to properly use the suggestion?

Any help is greatly appreciated :)

1

1 Answers

2
votes

I believe my issue had to do with a cached .terraform folder in the repo and some weird backend issue. ultimately the terraform 0.13upgrade did in indeed add the correct required provider info in version.tf .. if you're like me and still got errors try doing a terraform state list remove postgres resources delete .terraform / git clean, and then run terraform init / plan / apply / etc. Worked for me.