From 5b64641b77acd79b63fc167d37e6980ee4242957 Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 19 Aug 2021 12:53:03 -0500 Subject: [PATCH] upstream 9723 (#5112) (#9859) * Fix:9723 google_sql_user - "Root resource was present, but now absent" * Moved the declaration closer to the usage * Fetching the instance data Co-authored-by: Josh Angolano Signed-off-by: Modular Magician Co-authored-by: Josh Angolano --- .changelog/5112.txt | 3 +++ google/resource_sql_user.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changelog/5112.txt diff --git a/.changelog/5112.txt b/.changelog/5112.txt new file mode 100644 index 00000000000..93df627ec08 --- /dev/null +++ b/.changelog/5112.txt @@ -0,0 +1,3 @@ +```release-note:bug +sql: fixed bug in `google_sql_user` with CLOUD_IAM_USERs on POSTGRES. +``` diff --git a/google/resource_sql_user.go b/google/resource_sql_user.go index ddc41d54178..17659f10376 100644 --- a/google/resource_sql_user.go +++ b/google/resource_sql_user.go @@ -186,9 +186,15 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error { } var user *sqladmin.User - for _, currentUser := range users.Items { + databaseInstance, err := config.NewSqlAdminClient(userAgent).Instances.Get(project, instance).Do() + if err != nil { + return err + } - name = strings.Split(name, "@")[0] + for _, currentUser := range users.Items { + if !strings.Contains(databaseInstance.DatabaseVersion, "POSTGRES") { + name = strings.Split(name, "@")[0] + } if currentUser.Name == name { // Host can only be empty for postgres instances,