Skip to content

Commit

Permalink
Add support rootPassword property for MS SQL Server
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
kopachevsky authored and modular-magician committed Nov 26, 2019
1 parent 0df09ee commit 8b64361
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
12 changes: 12 additions & 0 deletions google-beta/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ func resourceSqlDatabaseInstance() *schema.Resource {
ForceNew: true,
},

"root_password": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Sensitive: true,
},

"ip_address": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -559,6 +566,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.
Expand Down
37 changes: 37 additions & 0 deletions google-beta/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,31 @@ func TestAccSqlDatabaseInstance_basicSecondGen(t *testing.T) {
})
}

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"},
},
},
})
}

func TestAccSqlDatabaseInstance_dontDeleteDefaultUserOnReplica(t *testing.T) {
t.Parallel()

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

var testGoogleSqlDatabaseInstance_basic3 = `
resource "google_sql_database_instance" "instance" {
name = "%s"
Expand All @@ -684,6 +710,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" {
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/sql_database_instance.html.markdown
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 8b64361

Please sign in to comment.