Skip to content

Commit

Permalink
upstream 9723 (#5112) (#9859)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Josh Angolano <[email protected]>
  • Loading branch information
modular-magician and Josh Angolano authored Aug 19, 2021
1 parent 4f10f86 commit 5b64641
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/5112.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
sql: fixed bug in `google_sql_user` with CLOUD_IAM_USERs on POSTGRES.
```
10 changes: 8 additions & 2 deletions google/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5b64641

Please sign in to comment.