Skip to content

Commit 00c1813

Browse files
authored
azurerm_mssql_elasticpool - add support for the high_availability_replica_count property (#31761)
[ENHANCEMENT] * `azurerm_mssql_elasticpool` - add support for the `high_availability_replica_count` property
1 parent 55c8f8c commit 00c1813

File tree

5 files changed

+159
-1
lines changed

5 files changed

+159
-1
lines changed

internal/services/mssql/mssql_elasticpool_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ func dataSourceMsSqlElasticpool() *pluginsdk.Resource {
104104
Computed: true,
105105
},
106106

107+
"high_availability_replica_count": {
108+
Type: pluginsdk.TypeInt,
109+
Computed: true,
110+
},
111+
107112
"tags": commonschema.TagsDataSource(),
108113
},
109114
}
@@ -159,6 +164,7 @@ func dataSourceMsSqlElasticpoolRead(d *pluginsdk.ResourceData, meta interface{})
159164
enclaveType = string(elasticpools.AlwaysEncryptedEnclaveTypeVBS)
160165
}
161166
d.Set("enclave_type", enclaveType)
167+
d.Set("high_availability_replica_count", props.HighAvailabilityReplicaCount)
162168
}
163169

164170
return tags.FlattenAndSet(d, model.Tags)

internal/services/mssql/mssql_elasticpool_resource.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"log"
10+
"strings"
1011
"time"
1112

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

207+
"high_availability_replica_count": {
208+
Type: pluginsdk.TypeInt,
209+
// NOTE: O+C can only be set for Hyperscale skus, which have a default value of 1
210+
Optional: true,
211+
Computed: true,
212+
ValidateFunc: validation.IntBetween(0, 4),
213+
},
214+
206215
"tags": commonschema.Tags(),
207216
},
208217

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

224+
if v, ok := diff.GetOk("high_availability_replica_count"); ok && v.(int) > 0 {
225+
skuRaw := diff.Get("sku").([]interface{})
226+
if len(skuRaw) > 0 {
227+
sku := skuRaw[0].(map[string]interface{})
228+
tier := sku["tier"].(string)
229+
if !strings.EqualFold(tier, "Hyperscale") {
230+
return fmt.Errorf("`high_availability_replica_count` can only be set when `sku.tier` is `Hyperscale`, got %q", tier)
231+
}
232+
}
233+
}
234+
215235
return nil
216236
},
217237

@@ -271,6 +291,10 @@ func resourceMsSqlElasticPoolCreateUpdate(d *pluginsdk.ResourceData, meta interf
271291
},
272292
}
273293

294+
if !d.GetRawConfig().AsValueMap()["high_availability_replica_count"].IsNull() {
295+
elasticPool.Properties.HighAvailabilityReplicaCount = pointer.To(int64(d.Get("high_availability_replica_count").(int)))
296+
}
297+
274298
// NOTE: The service default is actually nil/empty which indicates enclave is disabled. the value `Default` is NOT the default.
275299
if v, ok := d.GetOk("enclave_type"); ok && v.(string) != "" {
276300
elasticPool.Properties.PreferredEnclaveType = pointer.To(elasticpools.AlwaysEncryptedEnclaveType(v.(string)))
@@ -345,6 +369,7 @@ func resourceMssqlElasticPoolSetFlatten(d *pluginsdk.ResourceData, id *commonids
345369
licenseType = string(*props.LicenseType)
346370
}
347371
d.Set("license_type", licenseType)
372+
d.Set("high_availability_replica_count", pointer.From(props.HighAvailabilityReplicaCount))
348373

349374
if err := d.Set("per_database_settings", flattenMsSqlElasticPoolPerDatabaseSettings(props.PerDatabaseSettings)); err != nil {
350375
return fmt.Errorf("setting `per_database_settings`: %+v", err)

internal/services/mssql/mssql_elasticpool_resource_test.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,42 @@ func TestAccMsSqlElasticPool_dcFamilyVCoreEnclaveTypeError(t *testing.T) {
422422
})
423423
}
424424

425+
func TestAccMsSqlElasticPool_replicaCount(t *testing.T) {
426+
data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test")
427+
r := MssqlElasticpoolResource{}
428+
429+
data.ResourceTest(t, r, []acceptance.TestStep{
430+
{
431+
Config: r.highAvailabilityReplicaCount(data, 1),
432+
Check: acceptance.ComposeTestCheckFunc(
433+
check.That(data.ResourceName).ExistsInAzure(r),
434+
check.That(data.ResourceName).Key("high_availability_replica_count").HasValue("1"),
435+
),
436+
},
437+
data.ImportStep("max_size_gb"),
438+
{
439+
Config: r.highAvailabilityReplicaCount(data, 0),
440+
Check: acceptance.ComposeTestCheckFunc(
441+
check.That(data.ResourceName).ExistsInAzure(r),
442+
check.That(data.ResourceName).Key("high_availability_replica_count").HasValue("0"),
443+
),
444+
},
445+
data.ImportStep("max_size_gb"),
446+
})
447+
}
448+
449+
func TestAccMsSqlElasticPool_highAvailabilityReplicaCountNonHyperscaleError(t *testing.T) {
450+
data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test")
451+
r := MssqlElasticpoolResource{}
452+
453+
data.ResourceTest(t, r, []acceptance.TestStep{
454+
{
455+
Config: r.highAvailabilityReplicaCountNonHyperscale(data),
456+
ExpectError: regexp.MustCompile("`high_availability_replica_count` can only be set when `sku.tier` is `Hyperscale`"),
457+
},
458+
})
459+
}
460+
425461
func (MssqlElasticpoolResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
426462
id, err := commonids.ParseSqlElasticPoolID(state.ID)
427463
if err != nil {
@@ -847,3 +883,88 @@ func (r MssqlElasticpoolResource) hyperScale(data acceptance.TestData, enclaveTy
847883
func (r MssqlElasticpoolResource) hyperScaleUpdate(data acceptance.TestData, enclaveType string) string {
848884
return r.templateHyperScale(data, "HS_Gen5", "Hyperscale", 4, "Gen5", 0, 4, enclaveType)
849885
}
886+
887+
func (MssqlElasticpoolResource) highAvailabilityReplicaCount(data acceptance.TestData, replicaCount int) string {
888+
return fmt.Sprintf(`
889+
provider "azurerm" {
890+
features {}
891+
}
892+
893+
resource "azurerm_resource_group" "test" {
894+
name = "acctestRG-%[1]d"
895+
location = "%[2]s"
896+
}
897+
898+
resource "azurerm_mssql_server" "test" {
899+
name = "acctest%[1]d"
900+
resource_group_name = azurerm_resource_group.test.name
901+
location = azurerm_resource_group.test.location
902+
version = "12.0"
903+
administrator_login = "4dm1n157r470r"
904+
administrator_login_password = "4-v3ry-53cr37-p455w0rd"
905+
}
906+
907+
resource "azurerm_mssql_elasticpool" "test" {
908+
name = "acctest-pool-vcore-%[1]d"
909+
resource_group_name = azurerm_resource_group.test.name
910+
location = azurerm_resource_group.test.location
911+
server_name = azurerm_mssql_server.test.name
912+
high_availability_replica_count = %[3]d
913+
914+
sku {
915+
name = "HS_Gen5"
916+
tier = "Hyperscale"
917+
capacity = 4
918+
family = "Gen5"
919+
}
920+
921+
per_database_settings {
922+
min_capacity = 0.25
923+
max_capacity = 4
924+
}
925+
}
926+
`, data.RandomInteger, data.Locations.Primary, replicaCount)
927+
}
928+
929+
func (r MssqlElasticpoolResource) highAvailabilityReplicaCountNonHyperscale(data acceptance.TestData) string {
930+
return fmt.Sprintf(`
931+
provider "azurerm" {
932+
features {}
933+
}
934+
935+
resource "azurerm_resource_group" "test" {
936+
name = "acctestRG-%[1]d"
937+
location = "%[2]s"
938+
}
939+
940+
resource "azurerm_mssql_server" "test" {
941+
name = "acctest%[1]d"
942+
resource_group_name = azurerm_resource_group.test.name
943+
location = azurerm_resource_group.test.location
944+
version = "12.0"
945+
administrator_login = "4dm1n157r470r"
946+
administrator_login_password = "4-v3ry-53cr37-p455w0rd"
947+
}
948+
949+
resource "azurerm_mssql_elasticpool" "test" {
950+
name = "acctest-pool-gp-%[1]d"
951+
resource_group_name = azurerm_resource_group.test.name
952+
location = azurerm_resource_group.test.location
953+
server_name = azurerm_mssql_server.test.name
954+
max_size_gb = 5
955+
high_availability_replica_count = 2
956+
957+
sku {
958+
name = "GP_Gen5"
959+
tier = "GeneralPurpose"
960+
capacity = 4
961+
family = "Gen5"
962+
}
963+
964+
per_database_settings {
965+
min_capacity = 0.25
966+
max_capacity = 4
967+
}
968+
}
969+
`, data.RandomInteger, data.Locations.Primary)
970+
}

website/docs/d/mssql_elasticpool.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ output "elasticpool_id" {
4242

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

45+
* `high_availability_replica_count` - Specifies the number of high availability replicas for the elastic pool.
46+
4547
* `max_size_gb` - The max data size of the elastic pool in gigabytes.
4648

4749
* `max_size_bytes` - The max data size of the elastic pool in bytes.

website/docs/r/mssql_elasticpool.html.markdown

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ The following arguments are supported:
8787

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

90+
* `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`.
91+
92+
-> **Note:** The `high_availability_replica_count` property is only supported for `Hyperscale` tier elastic pools.
93+
9094
---
9195

9296
The `sku` block supports the following:
@@ -95,7 +99,7 @@ The `sku` block supports the following:
9599

96100
* `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).
97101

98-
* `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).
102+
* `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).
99103

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

0 commit comments

Comments
 (0)