terraform-provider-postgresql
terraform-provider-postgresql copied to clipboard
Support for data
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.
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
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.
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
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.
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