Skip to content

Commit

Permalink
Host (#7064) (#5059)
Browse files Browse the repository at this point in the history
fix hashicorp/terraform-provider-google#11365

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jan 7, 2023
1 parent c87a243 commit 3ea6e9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/7064.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
google_sql_user: added validation for host field.
```
17 changes: 17 additions & 0 deletions google-beta/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ func resourceSqlUserCreate(d *schema.ResourceData, meta interface{}) error {

mutexKV.Lock(instanceMutexKey(project, instance))
defer mutexKV.Unlock(instanceMutexKey(project, instance))

if v, ok := d.GetOk("host"); ok {
if v.(string) != "" {
var fetchedInstance *sqladmin.DatabaseInstance
err = retryTimeDuration(func() (rerr error) {
fetchedInstance, rerr = config.NewSqlAdminClient(userAgent).Instances.Get(project, instance).Do()
return rerr
}, d.Timeout(schema.TimeoutRead), isSqlOperationInProgressError)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("SQL Database Instance %q", d.Get("instance").(string)))
}
if !strings.Contains(fetchedInstance.DatabaseVersion, "MYSQL") {
return fmt.Errorf("Error: Host field is only supported for MySQL instances: %s", fetchedInstance.DatabaseVersion)
}
}
}

var op *sqladmin.Operation
insertFunc := func() error {
op, err = config.NewSqlAdminClient(userAgent).Users.Insert(project, instance,
Expand Down

0 comments on commit 3ea6e9b

Please sign in to comment.