cyrilgdn / terraform-provider-postgresql

Terraform PostgreSQL provider
https://www.terraform.io/docs/providers/postgresql/
Mozilla Public License 2.0
356 stars 181 forks source link

Support for `postgresql_databases` data source #374

Open igor-nikiforov opened 7 months ago

igor-nikiforov commented 7 months ago

Hello,

I have a requirement where I'm need to get a list of all databases from current PG instance and use it to create another non-PG related resources for each of database.

In PG it could be done with simple SQL query:

SELECT datname FROM pg_catalog.pg_database;

Example of data resource:

data "postgresql_databases" "this" {}

Result:

[db1, db2, db3]

Additionally, nice to have in-build regex filter to omit default databases like postgres, template0 and template1.

joaocc commented 6 months ago

This would indeed be great. This was one of the few points we found lacking when looking at this fine provider. In order to be able to use terraform to things like "ensuring PUBLIC is not granted connect on any existing database" or other such scenarios. Do you know if there is any sponsor program for this provider? Thx