From 9de6cc72379bc9c9b30adb3aef32c96da9204341 Mon Sep 17 00:00:00 2001 From: Andriy Kopachevskyy Date: Wed, 6 Nov 2019 16:56:51 +0200 Subject: [PATCH 1/3] Add support rootPassword property of google_sql_database_instance for SQL Server Added root_password parameter required MS SQL Server instance creation, ignored MySQL and PostgreSQL. Fix added both to beta and ga providers. Fixes #terraform-providers/terraform-provider-google/issues/4776 --- ... => resource_sql_database_instance.go.erb} | 17 ++++++++ ...resource_sql_database_instance_test.go.erb | 41 +++++++++++++++++++ .../r/sql_database_instance.html.markdown | 5 ++- 3 files changed, 62 insertions(+), 1 deletion(-) rename third_party/terraform/resources/{resource_sql_database_instance.go => resource_sql_database_instance.go.erb} (98%) diff --git a/third_party/terraform/resources/resource_sql_database_instance.go b/third_party/terraform/resources/resource_sql_database_instance.go.erb similarity index 98% rename from third_party/terraform/resources/resource_sql_database_instance.go rename to third_party/terraform/resources/resource_sql_database_instance.go.erb index 63f476395111..3d49674ae8ef 100644 --- a/third_party/terraform/resources/resource_sql_database_instance.go +++ b/third_party/terraform/resources/resource_sql_database_instance.go.erb @@ -1,3 +1,4 @@ +<% autogen_exception -%> package google import ( @@ -325,6 +326,15 @@ func resourceSqlDatabaseInstance() *schema.Resource { ForceNew: true, }, + <% unless version == 'ga' -%> + "root_password": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Sensitive: true, + }, + <% end -%> + "ip_address": { Type: schema.TypeList, Computed: true, @@ -559,6 +569,13 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) ReplicaConfiguration: expandReplicaConfiguration(d.Get("replica_configuration").([]interface{})), } + <% unless version == 'ga' -%> + // MSSQL Server require rootPassword to be set + if strings.Contains(instance.DatabaseVersion, "SQLSERVER") { + instance.RootPassword = d.Get("root_password").(string) + } + <% end -%> + // 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/third_party/terraform/tests/resource_sql_database_instance_test.go.erb b/third_party/terraform/tests/resource_sql_database_instance_test.go.erb index c0bac4580a49..ab6cd3dc0243 100644 --- a/third_party/terraform/tests/resource_sql_database_instance_test.go.erb +++ b/third_party/terraform/tests/resource_sql_database_instance_test.go.erb @@ -227,6 +227,33 @@ func TestAccSqlDatabaseInstance_basicSecondGen(t *testing.T) { }) } +<% unless version == 'ga' -%> +func TestAccSqlDatabaseInstance_basicMSSQL(t *testing.T) { + t.Parallel() + + databaseName := "tf-test-" + acctest.RandString(10) + rootPassword := acctest.RandString(15) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccSqlDatabaseInstanceDestroy, + 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"}, + }, + }, + }) +} +<% end -%> + func TestAccSqlDatabaseInstance_dontDeleteDefaultUserOnReplica(t *testing.T) { t.Parallel() @@ -679,6 +706,7 @@ resource "google_sql_database_instance" "instance" { } } ` + var testGoogleSqlDatabaseInstance_basic3 = ` resource "google_sql_database_instance" "instance" { name = "%s" @@ -689,6 +717,19 @@ resource "google_sql_database_instance" "instance" { } ` +<% unless version == 'ga' -%> +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" + } +} +` +<% end -%> + func testGoogleSqlDatabaseInstanceConfig_withoutReplica(instanceName string) string { return fmt.Sprintf(` resource "google_sql_database_instance" "instance" { diff --git a/third_party/terraform/website/docs/r/sql_database_instance.html.markdown b/third_party/terraform/website/docs/r/sql_database_instance.html.markdown index 8fe08ae2dd13..c3558c41d11a 100644 --- a/third_party/terraform/website/docs/r/sql_database_instance.html.markdown +++ b/third_party/terraform/website/docs/r/sql_database_instance.html.markdown @@ -192,9 +192,10 @@ The following arguments are supported: - - - -* `database_version` - (Optional, Default: `MYSQL_5_6`) The MySQL or PostgreSQL version to +* `database_version` - (Optional, Default: `MYSQL_5_6`) The MySQL, PostgreSQL or MS SQL Server (beta) version to use. Can be `MYSQL_5_6`, `MYSQL_5_7`, `POSTGRES_9_6` or `POSTGRES_11` (beta) for second-generation instances, or `MYSQL_5_5` or `MYSQL_5_6` for first-generation instances. + MS SQL Server supported versions: `SQLSERVER_2017_STANDARD`, `SQLSERVER_2017_ENTERPRISE`, `SQLSERVER_2017_EXPRESS`, `SQLSERVER_2017_WEB`, `SQLSERVER_ENTERPRISE_2016`. See [Second Generation Capabilities](https://cloud.google.com/sql/docs/1st-2nd-gen-differences) for more information. @@ -212,6 +213,8 @@ The following arguments are supported: * `replica_configuration` - (Optional) The configuration for replication. The configuration is detailed below. + +* `root_password` - (Optional, Beta) Initial root password. Required for MS SQL Server, ignored by MySQL and PostgreSQL. The required `settings` block supports: From 2baf105f4b6a54cb78bdebfca0f95e40e147ad48 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Tue, 26 Nov 2019 17:33:19 -0500 Subject: [PATCH 2/3] add link to beta docs --- .../website/docs/r/sql_database_instance.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/terraform/website/docs/r/sql_database_instance.html.markdown b/third_party/terraform/website/docs/r/sql_database_instance.html.markdown index c3558c41d11a..14ad11d4ba03 100644 --- a/third_party/terraform/website/docs/r/sql_database_instance.html.markdown +++ b/third_party/terraform/website/docs/r/sql_database_instance.html.markdown @@ -214,7 +214,7 @@ The following arguments are supported: * `replica_configuration` - (Optional) The configuration for replication. The configuration is detailed below. -* `root_password` - (Optional, Beta) Initial root password. Required for MS SQL Server, ignored by MySQL and PostgreSQL. +* `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. The required `settings` block supports: From b54223ec843ab89e855d86955271f0e38f13de1c Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 26 Nov 2019 23:24:38 +0000 Subject: [PATCH 3/3] Update tracked submodules -> HEAD on Tue Nov 26 23:24:38 UTC 2019 Tracked submodules are build/terraform-beta build/terraform-mapper build/terraform build/ansible build/inspec. --- build/terraform | 2 +- build/terraform-beta | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/terraform b/build/terraform index 4d2b96874a47..c9f75bd0e8d6 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit 4d2b96874a474fff754483f24fe669361f13be47 +Subproject commit c9f75bd0e8d61268b06c4c7433d53c25b844c3f8 diff --git a/build/terraform-beta b/build/terraform-beta index cfe3b7ae63ec..6fba41657cb0 160000 --- a/build/terraform-beta +++ b/build/terraform-beta @@ -1 +1 @@ -Subproject commit cfe3b7ae63eca36bf6ede4803a0d5816bd3d09a2 +Subproject commit 6fba41657cb03f1e86b85f0da7fd73d7950e7f00