Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host #5059

Merged

Host #5059

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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