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

Add Data Source For Retrieving Schema Names From A Database

Open SpencerBinXia opened this issue 3 years ago • 6 comments

Overview

This PR adds the new data source postgresql_schemas for retrieving schema names from a database.

The intended usage of this data source is so that it will no longer be necessary to type out schema names explicitly when using resources such as postgresql_grant to iterate over a list of schemas within a database. Instead, one may just loop over the list output from data.postgresql_schemas.

Example

data "postgresql_schemas" "example_retrieve_schemas" {
    database = "example_database"
    include_system_schemas = true # Optional argument that determines whether to include reserved system schemas.
    like_any_patterns = ["test%","%pg%"] # Optional expressions which will be pattern matched in the query using the LIKE ANY operators. 
    like_all_patterns = ["test%","%pg%"] # Optional expressions which will be pattern matched in the query using the LIKE ALL operators. 
    not_like_all_patterns =  ["example%"] # Optional expressions which will be pattern matched in the query using the NOT LIKE ALL operators. 
    regex_pattern = "^test_schema.*$" # Optional expression which will be pattern matched in the query using the ~ (regular expression match) operator.
}
output "example_database_schemas" {
    value = data.postgresql_schemas.example_retrieve_schemas.schemas
}

Issues

Closes #142

This issue was created by another member of our organization.

SpencerBinXia avatar Jan 04 '22 01:01 SpencerBinXia

Tests failed the first time due to I believe a different number of temporary pg_ schemas (pg_temp_1, pg_toast_temp_1, etc) than expected from local runs. Changed the acceptance tests to not rely on those 😌

SpencerBinXia avatar Jan 10 '22 15:01 SpencerBinXia

This looks really useful.. any movement on this?

briantist avatar Feb 16 '22 02:02 briantist

HI @cyrilgdn , could you please take another look at this PR or let us know any concerns you currently have preventing this from being merged?

SpencerBinXia avatar Apr 20 '22 18:04 SpencerBinXia

@SpencerBinXia I'm having a look, sorry for the delay.

I allowed myself to merge master in your PR.

cyrilgdn avatar May 07 '22 20:05 cyrilgdn

Hi @cyrilgdn, I liked your suggestions and made the appropriate changes to remove the need for pointers.

I opened a new PR https://github.com/cyrilgdn/terraform-provider-postgresql/pull/214 that also has changes for adding sequence and table data sources. It would be preferable if possible to get that PR merged and skip this one entirely, but I understand if you want to start with the smaller PR first!

SpencerBinXia avatar May 24 '22 02:05 SpencerBinXia

Hello any progress on this or #214 please?

tspearconquest avatar Jul 04 '22 03:07 tspearconquest

Closing this one: see https://github.com/cyrilgdn/terraform-provider-postgresql/pull/214

SpencerBinXia avatar Mar 16 '23 16:03 SpencerBinXia