Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix postgresql_user_mapping on AWS RDS Aurora #274

Merged
merged 4 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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