Postgres provider in terraform 0.12.x

Hello,

Is there any way to use postgres provider version higher than 1.7.2? I tried to use the newest version but have issue like below:

Terraform Version

❯ terraform -v
Terraform v0.12.31

Your version of Terraform is out of date! The latest version
is 1.2.9. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s)

  • getting provider

Terraform Configuration Files

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

Debug Output

❯ terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "random" (hashicorp/random) 3.4.3...

No provider "postgresql" plugins meet the constraint ">=1.17.1".

The version constraint is derived from the "version" argument within the
provider "postgresql" block in configuration. Child modules may also apply
provider version constraints. To view the provider versions requested by each
module in the current configuration, run "terraform providers".

To proceed, the version constraints for this provider must be relaxed by
either adjusting or removing the "version" argument in the provider blocks
throughout the configuration.

Warning: Provider source not supported in Terraform v0.12

  on main.tf line 3, in terraform:
   3:     postgresql = {
   4:       source  = "cyrilgdn/postgresql"
   5:       version = ">=1.17.1"
   6:     }

A source was declared for provider postgresql. Terraform v0.12 does not
support the provider source attribute. It will be ignored.

(and 4 more similar warnings elsewhere)

Error: no suitable version is available

Hi @debek,

As the warning message notes, Terraform v0.12 and earlier don’t yet know how to install providers from third-party namespaces such as cyrilgdn.

Therefore I assume what’s happening here is that your Terraform is looking at the older releases of this provider from when HashiCorp was distributing it, and so v1.7.2 is the newest version available. That was the last version published in the old way before the provider moved into a third-party namespace due to being maintained outside of HashiCorp.

If you wish to use newer versions of providers than what Terraform v0.12 can discover then the most general answer is that you will need to upgrade to Terraform v0.13 or later. Terraform v0.13 is the first version which supports automatic installation from third-party provider namespaces.

If you aren’t yet ready to upgrade then a more tactical solution would be to install the provider manually on your system. If you follow the link in the registry to the provider’s GitHub repository you should find that it has a “release” in GitHub for each of the versions available via the registry, which will have the distribution package .zip files attached to it. If you download the one for your platform and place it in one of the directories where Terraform v0.12 and earlier search for plugins then Terraform will hopefully discover it and use it.

The caveat is that newer versions of the provider might be using newer provider plugin protocol features that Terraform v0.12 doesn’t support, in which case the provider itself may not be compatible with v0.12. If that’s true then upgrading to a newer version of Terraform is likely to be the only viable answer.

Because Terraform v0.12 is obsolete there are no longer live docs about the directories it searches for provider plugins, but if I recall correctly the following locations should work:

  • On Unix-based systems (macOS, Linux, etc): $HOME/.terraform.d/plugins/terraform-provider-postgresql_v1.17.1
  • On Windows systems: %%APPDATA%%/terraform.d/plugins/terraform-provider-postgresql_v1.17.1.exe

For Terraform v0.12 and earlier, the executable file in the .zip package should be directly inside the plugins directory, without any intermediate subdirectories. I’ve shown the filenames from the v1.17.1 packages above. If you use a different version then you should use the filename from that archive instead, because Terraform will use the version number in the filename to determine whether the plugin matches the version constraints in your configuration.

(Note for future readers: This is a different legacy layout which is not true for Terraform v0.13 and later; the Provider Installation docs describe how this works in modern Terraform.)