Skip to content

Commit

Permalink
Ignore host when searching for postgres sql user in read from list (#…
Browse files Browse the repository at this point in the history
…3857)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and emilymye committed Jun 17, 2019
1 parent cf78e05 commit 36e0f27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"

sqladmin "google.golang.org/api/sqladmin/v1beta4"
)

Expand Down
12 changes: 7 additions & 5 deletions google/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error {

var user *sqladmin.User
for _, currentUser := range users.Items {
// The second part of this conditional is irrelevant for postgres instances because
// host and currentUser.Host will always both be empty.
if currentUser.Name == name && currentUser.Host == host {
user = currentUser
break
if currentUser.Name == name {
// Host can only be empty for postgres instances,
// so don't compare the host if the API host is empty.
if currentUser.Host == "" || currentUser.Host == host {
user = currentUser
break
}
}
}

Expand Down

0 comments on commit 36e0f27

Please sign in to comment.