Skip to content

Commit

Permalink
Add support rootPassword property for MS SQL Server (#2592)
Browse files Browse the repository at this point in the history
Merged PR #2592.
  • Loading branch information
kopachevsky authored and modular-magician committed Nov 26, 2019
1 parent bc59530 commit 9c921b4
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% autogen_exception -%>
package google

import (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -679,6 +706,7 @@ resource "google_sql_database_instance" "instance" {
}
}
`

var testGoogleSqlDatabaseInstance_basic3 = `
resource "google_sql_database_instance" "instance" {
name = "%s"
Expand All @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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](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:

Expand Down

0 comments on commit 9c921b4

Please sign in to comment.