Skip to content

Commit

Permalink
Merge pull request #5772 from aqche/azurerm_sql_database_zone_redundant
Browse files Browse the repository at this point in the history
`azurerm_sql_database` - support for `zone_redundant`
  • Loading branch information
tombuildsstuff authored Feb 19, 2020
2 parents caacb43 + e5f358a commit 7e03bc6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
11 changes: 10 additions & 1 deletion azurerm/internal/services/sql/resource_arm_sql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ func resourceArmSqlDatabase() *schema.Resource {
Default: false,
},

"zone_redundant": {
Type: schema.TypeBool,
Optional: true,
},

"tags": tags.Schema(),
},

Expand Down Expand Up @@ -351,6 +356,7 @@ func resourceArmSqlDatabaseCreateUpdate(d *schema.ResourceData, meta interface{}
resourceGroup := d.Get("resource_group_name").(string)
location := azure.NormalizeLocation(d.Get("location").(string))
createMode := d.Get("create_mode").(string)
zoneRedundant := d.Get("zone_redundant").(bool)
t := d.Get("tags").(map[string]interface{})

if features.ShouldResourcesBeImported() && d.IsNewResource() {
Expand All @@ -374,7 +380,8 @@ func resourceArmSqlDatabaseCreateUpdate(d *schema.ResourceData, meta interface{}
properties := sql.Database{
Location: utils.String(location),
DatabaseProperties: &sql.DatabaseProperties{
CreateMode: sql.CreateMode(createMode),
CreateMode: sql.CreateMode(createMode),
ZoneRedundant: utils.Bool(zoneRedundant),
},
Tags: tags.Expand(t),
}
Expand Down Expand Up @@ -570,6 +577,8 @@ func resourceArmSqlDatabaseRead(d *schema.ResourceData, meta interface{}) error
} else {
d.Set("read_scale", false)
}

d.Set("zone_redundant", props.ZoneRedundant)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,32 @@ func TestAccAzureRMSqlDatabase_readScale(t *testing.T) {
})
}

func TestAccAzureRMSqlDatabase_zoneRedundant(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_sql_database", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMSqlDatabaseDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMSqlDatabase_zoneRedundant(data, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "zone_redundant", "true"),
),
},
{
Config: testAccAzureRMSqlDatabase_zoneRedundant(data, false),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMSqlDatabaseExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "zone_redundant", "false"),
),
},
},
})
}

func testCheckAzureRMSqlDatabaseExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Sql.DatabasesClient
Expand Down Expand Up @@ -814,3 +840,32 @@ resource "azurerm_sql_database" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, readScale)
}

func testAccAzureRMSqlDatabase_zoneRedundant(data acceptance.TestData, zoneRedundant bool) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_sql_server" "test" {
name = "acctestsqlserver%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
version = "12.0"
administrator_login = "mradministrator"
administrator_login_password = "thisIsDog11"
}
resource "azurerm_sql_database" "test" {
name = "acctestdb%d"
resource_group_name = "${azurerm_resource_group.test.name}"
server_name = "${azurerm_sql_server.test.name}"
location = "${azurerm_resource_group.test.location}"
edition = "Premium"
collation = "SQL_Latin1_General_CP1_CI_AS"
max_size_bytes = "1073741824"
zone_redundant = %t
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, zoneRedundant)
}
2 changes: 2 additions & 0 deletions website/docs/r/sql_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ The following arguments are supported:

* `read_scale` - (Optional) Read-only connections will be redirected to a high-available replica. Please see [Use read-only replicas to load-balance read-only query workloads](https://docs.microsoft.com/en-us/azure/sql-database/sql-database-read-scale-out).

* `zone_redundant` - (Optional) Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.

* `tags` - (Optional) A mapping of tags to assign to the resource.

`import` supports the following:
Expand Down

0 comments on commit 7e03bc6

Please sign in to comment.