Skip to content

Commit

Permalink
fix postgresql_user_mapping on AWS RDS Aurora (#274)
Browse files Browse the repository at this point in the history
Co-authored-by: Cyril Gaudin <cyril.gaudin@gmail.com>
  • Loading branch information
fabiopaiva and cyrilgdn authored Mar 18, 2023
1 parent 3fb80ed commit 8c7f87e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions postgresql/resource_postgresql_user_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func resourcePostgreSQLUserMappingReadImpl(db *DBConnection, d *schema.ResourceD
defer deferredRollback(txn)

var userMappingOptions []string
query := "SELECT umoptions FROM pg_user_mappings WHERE usename = $1 and srvname = $2"
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))
switch {
case err == sql.ErrNoRows:
Expand All @@ -125,7 +125,7 @@ func resourcePostgreSQLUserMappingReadImpl(db *DBConnection, d *schema.ResourceD

mappedOptions := make(map[string]interface{})
for _, v := range userMappingOptions {
pair := strings.Split(v, "=")
pair := strings.SplitN(v, "=", 2)
mappedOptions[pair[0]] = pair[1]
}

Expand Down
15 changes: 15 additions & 0 deletions postgresql/resource_postgresql_user_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func TestAccPostgresqlUserMapping_Basic(t *testing.T) {
"postgresql_user_mapping.remote", "options.user", "admin"),
resource.TestCheckResourceAttr(
"postgresql_user_mapping.remote", "options.password", "pass"),
resource.TestCheckResourceAttr(
"postgresql_user_mapping.special_chars", "options.password", "pass=$*'"),
),
},
},
Expand Down Expand Up @@ -191,6 +193,19 @@ resource "postgresql_user_mapping" "remote" {
password = "pass"
}
}
resource "postgresql_role" "special" {
name = "special"
}
resource "postgresql_user_mapping" "special_chars" {
server_name = postgresql_server.myserver_postgres.server_name
user_name = postgresql_role.special.name
options = {
user = "admin"
password = "pass=$*'"
}
}
`

var testAccPostgresqlUserMappingChanges2 = `
Expand Down

0 comments on commit 8c7f87e

Please sign in to comment.