terraform-provider-postgresql icon indicating copy to clipboard operation
terraform-provider-postgresql copied to clipboard

Support for data

Open dbones opened this issue 3 years ago • 4 comments

Hi

at the moment this provider supports resources, but not data.

we have Postgres instances which are setup via another process, which mean we will need to reference Roles or Databases that already exist via the data technique.

dbones avatar Apr 27 '21 12:04 dbones

Hi @dbones ,

Thanks for opening this issue and sorry for the very very very late reply.

Out of curiosity, what do you want to reference on these data? Usually, users need to reference the name (of the database/role) but it is not really useful to load a data by its name for its name.

But if you need extra attributes, we could add data in this provider yes

cyrilgdn avatar Oct 22 '21 17:10 cyrilgdn

Here’s a use-case where I wish I could have used the postgres provider as a data source:

I have a database that contains user-provided domain names. I wanted to periodically run terraform to set DNS records using the domains in the database.

sbaildon avatar Oct 25 '21 19:10 sbaildon

we have a case wherein the server databases / tables / roles are created (managed) outside of the terraform which is being run

i would like to be able to reference these objects and use them when creating other objects

reference a database (data), add a table (resource) reference a role (data), add permissions to a database, tables etc (resources)

it's similar to how we can reference a Loadbalancer and add targets in the AWS provider.

hopefully, this helps

dbones avatar Nov 04 '21 03:11 dbones

It would be nice to have some way to reference information about the connection (most especially host and port). Since this is only known by the provider configuration, which is impossible to reference, it seems like perhaps a data object makes the most sense. Alternatively, it could be exposed on something like the postgresql_database resource.

The use-case for me is that I want to store a reference to the database connection URL from a module which wraps postgresql. Because it is best practice not to embed providers inside of modules, this means I have to pass the information both to my module and into the provider separately.

solarmosaic-kflorence avatar Feb 08 '22 17:02 solarmosaic-kflorence

I agree with @solarmosaic-kflorence,

As an example there a resources is in the AWS Provider to get the current region we are working on aws_region datasource. This region is configured on the provider (and can even be determined from environment variable). The datasource is pretty handy when working with module. The module can get the region instead of asking it as input variable :)

There are also information that could be dyanmic, or created by other services, like schemas, but these should be implemented with: https://github.com/cyrilgdn/terraform-provider-postgresql/issues/142

For the moment I see only two datasource that could be implemented (names can be changed of course) as others would only reference name attribute:

  • postgresql_current_database
  • postgresql_current_role

Would love to see this feature coming ! :D

a-meynard avatar Dec 02 '22 10:12 a-meynard