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

Including set max_size_bytes #2346

Merged
merged 11 commits into from
Jan 12, 2019
15 changes: 8 additions & 7 deletions azurerm/resource_arm_mssql_elasticpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ func resourceArmMsSqlElasticPool() *schema.Resource {
},

"max_size_bytes": {
katbyte marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeInt,
Computed: true,
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntAtLeast(0),
},

"zone_redundant": {
Expand Down Expand Up @@ -277,6 +279,10 @@ func resourceArmMsSqlElasticPoolCreateUpdate(d *schema.ResourceData, meta interf
},
}

if v, ok := d.GetOk("max_size_bytes"); ok {
elasticPool.MaxSizeBytes = utils.Int64(int64(v.(int)))
}

future, err := client.CreateOrUpdate(ctx, resGroup, serverName, elasticPoolName, elasticPool)
if err != nil {
return err
Expand Down Expand Up @@ -425,11 +431,6 @@ func flattenAzureRmMsSqlElasticPoolSku(resp *sql.Sku) []interface{} {

func flattenAzureRmMsSqlElasticPoolProperties(resp *sql.ElasticPoolProperties) []interface{} {
elasticPoolProperty := map[string]interface{}{}

if maxSizeBytes := resp.MaxSizeBytes; maxSizeBytes != nil {
elasticPoolProperty["max_size_bytes"] = *maxSizeBytes
}

elasticPoolProperty["state"] = string(resp.State)

if date := resp.CreationDate; date != nil {
Expand Down
51 changes: 42 additions & 9 deletions azurerm/resource_arm_mssql_elasticpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ func TestAccAzureRMMsSqlElasticPool_basic_DTU(t *testing.T) {
ri := tf.AccRandTimeInt()
config := testAccAzureRMMsSqlElasticPool_basic_DTU(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMsSqlElasticPoolDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMsSqlElasticPoolExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "sku.0.name", "BasicPool"),
resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Basic"),
resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "50"),
resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"),
resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "5"),
resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"),
resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"),
),
},
},
})
}

func TestAccAzureRMMsSqlElasticPool_standard_DTU(t *testing.T) {
resourceName := "azurerm_mssql_elasticpool.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMMsSqlElasticPool_standard_DTU(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down Expand Up @@ -78,7 +105,7 @@ func TestAccAzureRMMsSqlElasticPool_basic_vCore(t *testing.T) {
func TestAccAzureRMMsSqlElasticPool_disappears(t *testing.T) {
resourceName := "azurerm_mssql_elasticpool.test"
ri := tf.AccRandTimeInt()
config := testAccAzureRMMsSqlElasticPool_basic_DTU(ri, testLocation())
config := testAccAzureRMMsSqlElasticPool_standard_DTU(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -106,7 +133,7 @@ func TestAccAzureRMMsSqlElasticPool_resize_DTU(t *testing.T) {
resourceName := "azurerm_mssql_elasticpool.test"
ri := tf.AccRandTimeInt()
location := testLocation()
preConfig := testAccAzureRMMsSqlElasticPool_basic_DTU(ri, location)
preConfig := testAccAzureRMMsSqlElasticPool_standard_DTU(ri, location)
postConfig := testAccAzureRMMsSqlElasticPool_resize_DTU(ri, location)

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -257,11 +284,15 @@ func testCheckAzureRMMsSqlElasticPoolDisappears(resourceName string) resource.Te
}

func testAccAzureRMMsSqlElasticPool_basic_DTU(rInt int, location string) string {
return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "StandardPool", "Standard", 50, 0, 50)
return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "BasicPool", "Basic", 50, 5242880000, 0, 5)
}

func testAccAzureRMMsSqlElasticPool_standard_DTU(rInt int, location string) string {
return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "StandardPool", "Standard", 50, 53687091200, 0, 50)
}

func testAccAzureRMMsSqlElasticPool_resize_DTU(rInt int, location string) string {
return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "StandardPool", "Standard", 100, 50, 100)
return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "StandardPool", "Standard", 100, 107374182400, 50, 100)
}

func testAccAzureRMMsSqlElasticPool_basic_vCore(rInt int, location string) string {
Expand Down Expand Up @@ -293,6 +324,7 @@ resource "azurerm_mssql_elasticpool" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
server_name = "${azurerm_sql_server.test.name}"
max_size_bytes = 5368709120

sku {
name = "%[3]s"
Expand All @@ -309,7 +341,7 @@ resource "azurerm_mssql_elasticpool" "test" {
`, rInt, location, skuName, skuTier, skuCapacity, skuFamily, databaseSettingsMin, databaseSettingsMax)
}

func testAccAzureRMMsSqlElasticPool_DTU_Template(rInt int, location string, skuName string, skuTier string, skuCapacity int, databaseSettingsMin int, databaseSettingsMax int) string {
func testAccAzureRMMsSqlElasticPool_DTU_Template(rInt int, location string, skuName string, skuTier string, skuCapacity int, maxSizeBytes int, databaseSettingsMin int, databaseSettingsMax int) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
Expand All @@ -330,17 +362,18 @@ resource "azurerm_mssql_elasticpool" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
server_name = "${azurerm_sql_server.test.name}"

max_size_bytes = %[6]d

sku {
name = "%[3]s"
tier = "%[4]s"
capacity = %[5]d
}

per_database_settings {
min_capacity = %[6]d
max_capacity = %[7]d
min_capacity = %[7]d
max_capacity = %[8]d
}
}
`, rInt, location, skuName, skuTier, skuCapacity, databaseSettingsMin, databaseSettingsMax)
`, rInt, location, skuName, skuTier, skuCapacity, maxSizeBytes, databaseSettingsMin, databaseSettingsMax)
}
5 changes: 3 additions & 2 deletions website/docs/r/mssql_elasticpool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ resource "azurerm_mssql_elasticpool" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
server_name = "${azurerm_sql_server.test.name}"
max_size_bytes = 5368709120

sku {
name = "GP_Gen5"
Expand Down Expand Up @@ -63,6 +64,8 @@ The following arguments are supported:

* `per_database_settings` - (Required) A `per_database_settings` block as defined below.

* `max_size_bytes` - (Optional) The max data size of the elastic pool in bytes.

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

---
Expand Down Expand Up @@ -93,8 +96,6 @@ The following attributes are exported:

* `id` - The MsSQL Elastic Pool ID.

* `max_size_bytes` - The storage limit for the database elastic pool in bytes.

* `zone_redundant` - Whether or not this elastic pool is zone redundant.

## Import
Expand Down