Skip to content

Commit

Permalink
Add support rootPassword property of google_sql_database_instance for…
Browse files Browse the repository at this point in the history
… 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 #hashicorp/terraform-provider-google/issues/4776
  • Loading branch information
kopachevsky committed Nov 22, 2019
1 parent 3e52d73 commit 6fd9d76
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions third_party/terraform/resources/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
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,32 @@ 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 check disabled as long root_password property not stored in state
ImportStateVerify: false,
},
},
})
}


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

Expand Down Expand Up @@ -689,6 +715,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" {
name = "%s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ The following arguments are supported:

* `replica_configuration` - (Optional) The configuration for replication. The
configuration is detailed below.

* `root_password` - (Optional) Required for MS SQL Server, ignored MySQL and PostgreSQL.

The required `settings` block supports:

Expand Down

0 comments on commit 6fd9d76

Please sign in to comment.