From 01a056f7cf30c2d9e837b2b073473aa7314a1b01 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Sat, 7 Jan 2023 00:26:27 +0000 Subject: [PATCH] Host (#7064) fix https://github.com/hashicorp/terraform-provider-google/issues/11365 Signed-off-by: Modular Magician --- .changelog/7064.txt | 3 +++ google-beta/resource_sql_user.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 .changelog/7064.txt diff --git a/.changelog/7064.txt b/.changelog/7064.txt new file mode 100644 index 0000000000..b225322115 --- /dev/null +++ b/.changelog/7064.txt @@ -0,0 +1,3 @@ +```release-note:bug +google_sql_user: added validation for host field. +``` diff --git a/google-beta/resource_sql_user.go b/google-beta/resource_sql_user.go index 73b0379400..64446fd360 100644 --- a/google-beta/resource_sql_user.go +++ b/google-beta/resource_sql_user.go @@ -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,