Skip to content

Commit

Permalink
Resource google_sql_database_instance root_password (MS SQL) for GA (#…
Browse files Browse the repository at this point in the history
…3638) (#6601)

Co-authored-by: Edward Sun <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Jun 16, 2020
1 parent 4f7b9b0 commit 903d80d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/3638.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
sql: Moved `google_sql_database_instance` `root_password` (MS SQL) to GA
```
13 changes: 13 additions & 0 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
36 changes: 36 additions & 0 deletions google/resource_sql_database_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/sql_database_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 903d80d

Please sign in to comment.