Skip to content
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
6 changes: 6 additions & 0 deletions internal/services/mssql/mssql_elasticpool_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func dataSourceMsSqlElasticpool() *pluginsdk.Resource {
Computed: true,
},

"high_availability_replica_count": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"tags": commonschema.TagsDataSource(),
},
}
Expand Down Expand Up @@ -159,6 +164,7 @@ func dataSourceMsSqlElasticpoolRead(d *pluginsdk.ResourceData, meta interface{})
enclaveType = string(elasticpools.AlwaysEncryptedEnclaveTypeVBS)
}
d.Set("enclave_type", enclaveType)
d.Set("high_availability_replica_count", props.HighAvailabilityReplicaCount)
}

return tags.FlattenAndSet(d, model.Tags)
Expand Down
25 changes: 25 additions & 0 deletions internal/services/mssql/mssql_elasticpool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
Expand Down Expand Up @@ -203,6 +204,14 @@ func resourceMsSqlElasticPool() *pluginsdk.Resource {
}, false),
},

"high_availability_replica_count": {
Type: pluginsdk.TypeInt,
// NOTE: O+C can only be set for Hyperscale skus, which have a default value of 1
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(0, 4),
},

"tags": commonschema.Tags(),
},

Expand All @@ -212,6 +221,17 @@ func resourceMsSqlElasticPool() *pluginsdk.Resource {
return err
}

if v, ok := diff.GetOk("high_availability_replica_count"); ok && v.(int) > 0 {
skuRaw := diff.Get("sku").([]interface{})
if len(skuRaw) > 0 {
sku := skuRaw[0].(map[string]interface{})
tier := sku["tier"].(string)
if !strings.EqualFold(tier, "Hyperscale") {
return fmt.Errorf("`high_availability_replica_count` can only be set when `sku.tier` is `Hyperscale`, got %q", tier)
}
}
}

return nil
},

Expand Down Expand Up @@ -271,6 +291,10 @@ func resourceMsSqlElasticPoolCreateUpdate(d *pluginsdk.ResourceData, meta interf
},
}

if !d.GetRawConfig().AsValueMap()["high_availability_replica_count"].IsNull() {
elasticPool.Properties.HighAvailabilityReplicaCount = pointer.To(int64(d.Get("high_availability_replica_count").(int)))
}

// NOTE: The service default is actually nil/empty which indicates enclave is disabled. the value `Default` is NOT the default.
if v, ok := d.GetOk("enclave_type"); ok && v.(string) != "" {
elasticPool.Properties.PreferredEnclaveType = pointer.To(elasticpools.AlwaysEncryptedEnclaveType(v.(string)))
Expand Down Expand Up @@ -345,6 +369,7 @@ func resourceMssqlElasticPoolSetFlatten(d *pluginsdk.ResourceData, id *commonids
licenseType = string(*props.LicenseType)
}
d.Set("license_type", licenseType)
d.Set("high_availability_replica_count", pointer.From(props.HighAvailabilityReplicaCount))

if err := d.Set("per_database_settings", flattenMsSqlElasticPoolPerDatabaseSettings(props.PerDatabaseSettings)); err != nil {
return fmt.Errorf("setting `per_database_settings`: %+v", err)
Expand Down
121 changes: 121 additions & 0 deletions internal/services/mssql/mssql_elasticpool_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,42 @@ func TestAccMsSqlElasticPool_dcFamilyVCoreEnclaveTypeError(t *testing.T) {
})
}

func TestAccMsSqlElasticPool_replicaCount(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test")
r := MssqlElasticpoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.highAvailabilityReplicaCount(data, 1),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("high_availability_replica_count").HasValue("1"),
),
},
data.ImportStep("max_size_gb"),
{
Config: r.highAvailabilityReplicaCount(data, 0),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("high_availability_replica_count").HasValue("0"),
),
},
data.ImportStep("max_size_gb"),
})
}

func TestAccMsSqlElasticPool_highAvailabilityReplicaCountNonHyperscaleError(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test")
r := MssqlElasticpoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.highAvailabilityReplicaCountNonHyperscale(data),
ExpectError: regexp.MustCompile("`high_availability_replica_count` can only be set when `sku.tier` is `Hyperscale`"),
},
})
}

func (MssqlElasticpoolResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := commonids.ParseSqlElasticPoolID(state.ID)
if err != nil {
Expand Down Expand Up @@ -847,3 +883,88 @@ func (r MssqlElasticpoolResource) hyperScale(data acceptance.TestData, enclaveTy
func (r MssqlElasticpoolResource) hyperScaleUpdate(data acceptance.TestData, enclaveType string) string {
return r.templateHyperScale(data, "HS_Gen5", "Hyperscale", 4, "Gen5", 0, 4, enclaveType)
}

func (MssqlElasticpoolResource) highAvailabilityReplicaCount(data acceptance.TestData, replicaCount int) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}

resource "azurerm_mssql_server" "test" {
name = "acctest%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
version = "12.0"
administrator_login = "4dm1n157r470r"
administrator_login_password = "4-v3ry-53cr37-p455w0rd"
}

resource "azurerm_mssql_elasticpool" "test" {
name = "acctest-pool-vcore-%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
server_name = azurerm_mssql_server.test.name
high_availability_replica_count = %[3]d

sku {
name = "HS_Gen5"
tier = "Hyperscale"
capacity = 4
family = "Gen5"
}

per_database_settings {
min_capacity = 0.25
max_capacity = 4
}
}
`, data.RandomInteger, data.Locations.Primary, replicaCount)
}

func (r MssqlElasticpoolResource) highAvailabilityReplicaCountNonHyperscale(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}

resource "azurerm_mssql_server" "test" {
name = "acctest%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
version = "12.0"
administrator_login = "4dm1n157r470r"
administrator_login_password = "4-v3ry-53cr37-p455w0rd"
}

resource "azurerm_mssql_elasticpool" "test" {
name = "acctest-pool-gp-%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
server_name = azurerm_mssql_server.test.name
max_size_gb = 5
high_availability_replica_count = 2

sku {
name = "GP_Gen5"
tier = "GeneralPurpose"
capacity = 4
family = "Gen5"
}

per_database_settings {
min_capacity = 0.25
max_capacity = 4
}
}
`, data.RandomInteger, data.Locations.Primary)
}
2 changes: 2 additions & 0 deletions website/docs/d/mssql_elasticpool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ output "elasticpool_id" {

* `location` - Specifies the supported Azure location where the resource exists.

* `high_availability_replica_count` - Specifies the number of high availability replicas for the elastic pool.

* `max_size_gb` - The max data size of the elastic pool in gigabytes.

* `max_size_bytes` - The max data size of the elastic pool in bytes.
Expand Down
6 changes: 5 additions & 1 deletion website/docs/r/mssql_elasticpool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ The following arguments are supported:

* `license_type` - (Optional) Specifies the license type applied to this database. Possible values are `LicenseIncluded` and `BasePrice`.

* `high_availability_replica_count` - (Optional) Specifies the number of high availability replicas for the elastic pool. Defaults to `1`. Possible values are between `0` and `4`.

-> **Note:** The `high_availability_replica_count` property is only supported for `Hyperscale` tier elastic pools.

---

The `sku` block supports the following:
Expand All @@ -95,7 +99,7 @@ The `sku` block supports the following:

* `capacity` - (Required) The scale up/out capacity, representing server's compute units. For more information see the documentation for your Elasticpool configuration: [vCore-based](https://docs.microsoft.com/azure/sql-database/sql-database-vcore-resource-limits-elastic-pools) or [DTU-based](https://docs.microsoft.com/azure/sql-database/sql-database-dtu-resource-limits-elastic-pools).

* `tier` - (Required) The tier of the particular SKU. Possible values are `GeneralPurpose`, `BusinessCritical`, `Basic`, `Standard`, `Premium`, or `HyperScale`. For more information see the documentation for your Elasticpool configuration: [vCore-based](https://docs.microsoft.com/azure/sql-database/sql-database-vcore-resource-limits-elastic-pools) or [DTU-based](https://docs.microsoft.com/azure/sql-database/sql-database-dtu-resource-limits-elastic-pools).
* `tier` - (Required) The tier of the particular SKU. Possible values are `GeneralPurpose`, `BusinessCritical`, `Basic`, `Standard`, `Premium`, or `Hyperscale`. For more information see the documentation for your Elasticpool configuration: [vCore-based](https://docs.microsoft.com/azure/sql-database/sql-database-vcore-resource-limits-elastic-pools) or [DTU-based](https://docs.microsoft.com/azure/sql-database/sql-database-dtu-resource-limits-elastic-pools).

* `family` - (Optional) The `family` of hardware `Gen4`, `Gen5`, `Fsv2`, `MOPRMS`, `PRMS`, or `DC`.

Expand Down
Loading