diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl index d85d72dd999a..160f138a7519 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl @@ -283,10 +283,9 @@ func ResourceSqlDatabaseInstance() *schema.Resource { }, }, "time_zone": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Description: `The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format.`, + Type: schema.TypeString, + Optional: true, + Description: `The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format.`, }, "availability_type": { Type: schema.TypeString, @@ -1979,7 +1978,32 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{}) } } - return resourceSqlDatabaseInstanceRead(d, meta) + // Check if timezone is updated + if d.HasChange("settings.0.time_zone") { + timezone := d.Get("settings.0.time_zone").(string) + instance = &sqladmin.DatabaseInstance{Settings: &sqladmin.Settings{TimeZone: timezone}} + err = transport_tpg.Retry(transport_tpg.RetryOptions{ + RetryFunc: func() (rerr error) { + op, rerr = config.NewSqlAdminClient(userAgent).Instances.Patch(project, d.Get("name").(string), instance).Do() + return err + }, + Timeout: d.Timeout(schema.TimeoutUpdate), + ErrorRetryPredicates: []transport_tpg.RetryErrorPredicateFunc{transport_tpg.IsSqlOperationInProgressError}, + }) + if err != nil { + return fmt.Errorf("Error, failed to patch instance settings for %s: %s", instance.Name, err) + } + err = SqlAdminOperationWaitTime(config, op, project, "Patch Instance", userAgent, d.Timeout(schema.TimeoutUpdate)) + if err != nil { + return err + } + err = resourceSqlDatabaseInstanceRead(d, meta) + if err != nil { + return err + } + } + + return resourceSqlDatabaseInstanceRead(d, meta) } func maintenanceVersionDiffSuppress(_, old, new string, _ *schema.ResourceData) bool { diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index 71ee6758c746..ee76c51dd43d 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -2076,6 +2076,41 @@ func TestAccSqlDatabaseInstance_rootPasswordShouldBeUpdatable(t *testing.T) { }) } +func TestAccSqlDatabaseInstance_SqlServerTimezoneUpdate(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + rootPassword := acctest.RandString(t, 15) + timezone := "Eastern Standard Time" + timezoneUpdate := "Pacific Standard Time" + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testGoogleSqlDatabaseInstance_SqlServerTimezone(instanceName, rootPassword, timezone), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"}, + }, + { + Config: testGoogleSqlDatabaseInstance_SqlServerTimezone(instanceName, rootPassword, timezoneUpdate), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection", "root_password"}, + }, + }, + }) +} + func TestAccSqlDatabaseInstance_activationPolicy(t *testing.T) { t.Parallel() @@ -2684,6 +2719,25 @@ resource "google_sql_database_instance" "instance" { }`, instanceName, tier, edition) } +func testGoogleSqlDatabaseInstance_SqlServerTimezone(instance, rootPassword, timezone string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "SQLSERVER_2017_STANDARD" + root_password = "%s" + deletion_protection = false + settings { + tier = "db-custom-1-3840" + ip_configuration { + ipv4_enabled = "true" + } + time_zone = "%s" + } +} +`, instance, rootPassword, timezone) +} + func testGoogleSqlDatabaseInstance_SqlServerAuditConfig(databaseName, rootPassword, bucketName, uploadInterval, retentionInterval string) string { return fmt.Sprintf(` resource "google_storage_bucket" "gs-bucket" {