Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_sql_database - support for zone_redundant #5772

Merged
merged 4 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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