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

Add Data Sources For Retrieving Schema, Sequence and Table Names From A Database

Open SpencerBinXia opened this issue 2 years ago • 4 comments

An expanded version of PR https://github.com/cyrilgdn/terraform-provider-postgresql/pull/171 which adds three new data sources for retrieving the names of schemas, sequences and tables respectively from a database.

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.
}
data "postgresql_sequences" "example_retrieve_sequences" {
  database = "example_database"
  schemas = ["test_schema","test_schema1","test_schema2"] # Optional list of PostgreSQL schema(s) which will be queried for sequence names. Queries all schemas in the database by default.
  like_any_patterns = ["test%","%pg%"] 
  like_all_patterns = ["test%","%pg%"] 
  not_like_all_patterns = ["example%"]
  regex_pattern = "^test_.*$"
}
data "postgresql_tables" "example_retrieve_tables" {
  database = "example_database"
  schemas = ["test_schema","test_schema1","test_schema2"]
  table_types = ["BASE TABLE"] # Optional list of PostgreSQL table types which will be queried for table names. Includes all table types by default (including views and temp tables). Use 'BASE TABLE' for normal tables only.
  like_any_patterns = ["test%","%pg%"] 
  like_all_patterns = ["test%","%pg%"] 
  not_like_all_patterns = ["example%"]
  regex_pattern = "^test_.*$"
}

Issues

Closes #142

SpencerBinXia avatar May 24 '22 01:05 SpencerBinXia

Hello, just curious if there is any progress on this?

tspearconquest avatar Jul 04 '22 03:07 tspearconquest

Hey, Thanks for your awesome work! I'll try to have a look this week or next week-end

cyrilgdn avatar Jul 04 '22 10:07 cyrilgdn

Hi @cyrilgdn sorry to poke at you for this. Just hoping to see this merged soon. Thanks for your help! :)

tspearconquest avatar Jul 25 '22 21:07 tspearconquest

Hello, any news on this ? this will be useful for sure.

vr avatar Oct 19 '22 08:10 vr

@cyrilgdn hi! is there anything that's blocking this? This is something that we could definitely use for schema grants!

irmiller22 avatar Nov 22 '22 19:11 irmiller22