Skip to content

Commit 8c7f87e

Browse files
fix postgresql_user_mapping on AWS RDS Aurora (#274)
Co-authored-by: Cyril Gaudin <[email protected]>
1 parent 3fb80ed commit 8c7f87e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

postgresql/resource_postgresql_user_mapping.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func resourcePostgreSQLUserMappingReadImpl(db *DBConnection, d *schema.ResourceD
112112
defer deferredRollback(txn)
113113

114114
var userMappingOptions []string
115-
query := "SELECT umoptions FROM pg_user_mappings WHERE usename = $1 and srvname = $2"
115+
query := "SELECT umoptions FROM information_schema._pg_user_mappings WHERE authorization_identifier = $1 and foreign_server_name = $2"
116116
err = txn.QueryRow(query, username, serverName).Scan(pq.Array(&userMappingOptions))
117117
switch {
118118
case err == sql.ErrNoRows:
@@ -125,7 +125,7 @@ func resourcePostgreSQLUserMappingReadImpl(db *DBConnection, d *schema.ResourceD
125125

126126
mappedOptions := make(map[string]interface{})
127127
for _, v := range userMappingOptions {
128-
pair := strings.Split(v, "=")
128+
pair := strings.SplitN(v, "=", 2)
129129
mappedOptions[pair[0]] = pair[1]
130130
}
131131

postgresql/resource_postgresql_user_mapping_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func TestAccPostgresqlUserMapping_Basic(t *testing.T) {
3232
"postgresql_user_mapping.remote", "options.user", "admin"),
3333
resource.TestCheckResourceAttr(
3434
"postgresql_user_mapping.remote", "options.password", "pass"),
35+
resource.TestCheckResourceAttr(
36+
"postgresql_user_mapping.special_chars", "options.password", "pass=$*'"),
3537
),
3638
},
3739
},
@@ -191,6 +193,19 @@ resource "postgresql_user_mapping" "remote" {
191193
password = "pass"
192194
}
193195
}
196+
197+
resource "postgresql_role" "special" {
198+
name = "special"
199+
}
200+
201+
resource "postgresql_user_mapping" "special_chars" {
202+
server_name = postgresql_server.myserver_postgres.server_name
203+
user_name = postgresql_role.special.name
204+
options = {
205+
user = "admin"
206+
password = "pass=$*'"
207+
}
208+
}
194209
`
195210

196211
var testAccPostgresqlUserMappingChanges2 = `

0 commit comments

Comments
 (0)