From cdcab1748f902263824023bee94e3d6ce4fb38ad Mon Sep 17 00:00:00 2001 From: Alessandro De Maria Date: Sat, 19 Oct 2024 09:51:40 +0100 Subject: [PATCH] fix(user_mapping): Adds fallback query to fix #327 (#469) https://github.com/cyrilgdn/terraform-provider-postgresql/pull/274 broke support for GCP Cloud Postgres and perhaps other versions. fix: #327 --- postgresql/resource_postgresql_user_mapping.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/postgresql/resource_postgresql_user_mapping.go b/postgresql/resource_postgresql_user_mapping.go index 15b9136c..891ef2b0 100644 --- a/postgresql/resource_postgresql_user_mapping.go +++ b/postgresql/resource_postgresql_user_mapping.go @@ -114,6 +114,13 @@ func resourcePostgreSQLUserMappingReadImpl(db *DBConnection, d *schema.ResourceD var userMappingOptions []string query := "SELECT umoptions FROM information_schema._pg_user_mappings WHERE authorization_identifier = $1 and foreign_server_name = $2" err = txn.QueryRow(query, username, serverName).Scan(pq.Array(&userMappingOptions)) + + if err != sql.ErrNoRows && err != nil { + // Fallback to pg_user_mappings table if information_schema._pg_user_mappings is not available + query := "SELECT umoptions FROM pg_user_mappings WHERE usename = $1 and srvname = $2" + err = txn.QueryRow(query, username, serverName).Scan(pq.Array(&userMappingOptions)) + } + switch { case err == sql.ErrNoRows: log.Printf("[WARN] PostgreSQL user mapping (%s) for server (%s) not found", username, serverName)