From fb8d6c700edb0c118b6426e401742478ce2ba7e7 Mon Sep 17 00:00:00 2001 From: megan07 Date: Thu, 19 Aug 2021 12:41:51 -0500 Subject: [PATCH] upstream 9723 (#5112) * 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 --- .../terraform/resources/resource_sql_user.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/resources/resource_sql_user.go b/mmv1/third_party/terraform/resources/resource_sql_user.go index ddc41d541780..17659f103761 100644 --- a/mmv1/third_party/terraform/resources/resource_sql_user.go +++ b/mmv1/third_party/terraform/resources/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,