From 903d80df70330f1895208191156ebcfc000af2c3 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 15 Jun 2020 17:15:01 -0700 Subject: [PATCH] Resource google_sql_database_instance root_password (MS SQL) for GA (#3638) (#6601) Co-authored-by: Edward Sun Signed-off-by: Modular Magician Co-authored-by: Edward Sun --- .changelog/3638.txt | 3 ++ google/resource_sql_database_instance.go | 13 +++++++ google/resource_sql_database_instance_test.go | 36 +++++++++++++++++++ .../r/sql_database_instance.html.markdown | 2 +- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .changelog/3638.txt diff --git a/.changelog/3638.txt b/.changelog/3638.txt new file mode 100644 index 00000000000..36a94ce8453 --- /dev/null +++ b/.changelog/3638.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +sql: Moved `google_sql_database_instance` `root_password` (MS SQL) to GA +``` diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index 57a76ebbfe8..e88bd9e7137 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -359,6 +359,14 @@ settings.backup_configuration.binary_log_enabled are both set to true.`, Description: `The MySQL, PostgreSQL or SQL Server (beta) version to use. Supported values include MYSQL_5_6, MYSQL_5_7, POSTGRES_9_6,POSTGRES_11, SQLSERVER_2017_STANDARD, SQLSERVER_2017_ENTERPRISE, SQLSERVER_2017_EXPRESS, SQLSERVER_2017_WEB. Database Version Policies includes an up-to-date reference of supported versions.`, }, + "root_password": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Sensitive: true, + Description: `Initial root password. Required for MS SQL Server, ignored by MySQL and PostgreSQL.`, + }, + "ip_address": { Type: schema.TypeList, Computed: true, @@ -618,6 +626,11 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) ReplicaConfiguration: expandReplicaConfiguration(d.Get("replica_configuration").([]interface{})), } + // MSSQL Server require rootPassword to be set + if strings.Contains(instance.DatabaseVersion, "SQLSERVER") { + instance.RootPassword = d.Get("root_password").(string) + } + // Modifying a replica during Create can cause problems if the master is // modified at the same time. Lock the master until we're done in order // to prevent that. diff --git a/google/resource_sql_database_instance_test.go b/google/resource_sql_database_instance_test.go index ada46baecf3..ba59be6aa08 100644 --- a/google/resource_sql_database_instance_test.go +++ b/google/resource_sql_database_instance_test.go @@ -197,6 +197,31 @@ func TestAccSqlDatabaseInstance_basicSecondGen(t *testing.T) { }) } +func TestAccSqlDatabaseInstance_basicMSSQL(t *testing.T) { + t.Parallel() + + databaseName := "tf-test-" + randString(t, 10) + rootPassword := randString(t, 15) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: fmt.Sprintf( + testGoogleSqlDatabaseInstance_basic_mssql, databaseName, rootPassword), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"root_password"}, + }, + }, + }) +} + func TestAccSqlDatabaseInstance_dontDeleteDefaultUserOnReplica(t *testing.T) { t.Parallel() @@ -623,6 +648,17 @@ resource "google_sql_database_instance" "instance" { } ` +var testGoogleSqlDatabaseInstance_basic_mssql = ` +resource "google_sql_database_instance" "instance" { + name = "%s" + database_version = "SQLSERVER_2017_STANDARD" + root_password = "%s" + settings { + tier = "db-custom-1-3840" + } +} +` + func testGoogleSqlDatabaseInstanceConfig_withoutReplica(instanceName string) string { return fmt.Sprintf(` resource "google_sql_database_instance" "instance" { diff --git a/website/docs/r/sql_database_instance.html.markdown b/website/docs/r/sql_database_instance.html.markdown index 7441ab2329a..a0409f839e4 100644 --- a/website/docs/r/sql_database_instance.html.markdown +++ b/website/docs/r/sql_database_instance.html.markdown @@ -214,7 +214,7 @@ includes an up-to-date reference of supported versions. * `replica_configuration` - (Optional) The configuration for replication. The configuration is detailed below. -* `root_password` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Initial root password. Required for MS SQL Server, ignored by MySQL and PostgreSQL. +* `root_password` - (Optional) Initial root password. Required for MS SQL Server, ignored by MySQL and PostgreSQL. * `encryption_key_name` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) The full path to the encryption key used for the CMEK disk encryption. Setting