diff --git a/internal/services/mssql/mssql_database_resource.go b/internal/services/mssql/mssql_database_resource.go index 1e48729907b1..727d05fe6ce5 100644 --- a/internal/services/mssql/mssql_database_resource.go +++ b/internal/services/mssql/mssql_database_resource.go @@ -277,6 +277,7 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er // NOTE: If the database is being added to an elastic pool, we need to GET the elastic pool and check // if the 'enclave_type' matches. If they don't we need to raise an error stating that they must match. elasticPoolId := d.Get("elastic_pool_id").(string) + elasticPoolSku := "" if elasticPoolId != "" { elasticId, err := commonids.ParseSqlElasticPoolID(elasticPoolId) if err != nil { @@ -288,12 +289,18 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er return fmt.Errorf("retrieving %s: %s", elasticId, err) } - if elasticPool.Model != nil && elasticPool.Model.Properties != nil && elasticPool.Model.Properties.PreferredEnclaveType != nil { - elasticEnclaveType := string(pointer.From(elasticPool.Model.Properties.PreferredEnclaveType)) - databaseEnclaveType := string(enclaveType) + if elasticPool.Model != nil { + if elasticPool.Model.Properties != nil && elasticPool.Model.Properties.PreferredEnclaveType != nil { + elasticEnclaveType := string(pointer.From(elasticPool.Model.Properties.PreferredEnclaveType)) + databaseEnclaveType := string(enclaveType) - if !strings.EqualFold(elasticEnclaveType, databaseEnclaveType) { - return fmt.Errorf("adding the %s with enclave type %q to the %s with enclave type %q is not supported. Before adding a database to an elastic pool please ensure that the 'enclave_type' is the same for both the database and the elastic pool", id, databaseEnclaveType, elasticId, elasticEnclaveType) + if !strings.EqualFold(elasticEnclaveType, databaseEnclaveType) { + return fmt.Errorf("adding the %s with enclave type %q to the %s with enclave type %q is not supported. Before adding a database to an elastic pool please ensure that the 'enclave_type' is the same for both the database and the elastic pool", id, databaseEnclaveType, elasticId, elasticEnclaveType) + } + } + + if elasticPool.Model.Sku != nil { + elasticPoolSku = elasticPool.Model.Sku.Name } } } @@ -613,7 +620,7 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er securityAlertPolicyPayload.Properties = shortTermSecurityAlertPolicyProps } - if strings.HasPrefix(skuName, "HS") { + if strings.HasPrefix(skuName, "HS") || strings.HasPrefix(elasticPoolSku, "HS") { securityAlertPolicyPayload.Properties.DiffBackupIntervalInHours = nil } diff --git a/internal/services/mssql/mssql_database_resource_test.go b/internal/services/mssql/mssql_database_resource_test.go index 77150fc08e34..033a4dfe36b5 100644 --- a/internal/services/mssql/mssql_database_resource_test.go +++ b/internal/services/mssql/mssql_database_resource_test.go @@ -1006,6 +1006,21 @@ func TestAccMsSqlDatabase_namedReplicationZoneRedundant(t *testing.T) { }) } +func TestAccMsSqlDatabase_elasticPoolHS(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_mssql_database", "test") + r := MsSqlDatabaseResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.elasticPoolHS(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (MsSqlDatabaseResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := commonids.ParseSqlDatabaseID(state.ID) if err != nil { @@ -2243,3 +2258,35 @@ resource "azurerm_mssql_database" "secondary" { } `, r.template(data), data.RandomInteger) } + +func (r MsSqlDatabaseResource) elasticPoolHS(data acceptance.TestData) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_mssql_elasticpool" "test" { + name = "acctest-pool-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + server_name = azurerm_mssql_server.test.name + + sku { + name = "HS_Gen5" + tier = "Hyperscale" + family = "Gen5" + capacity = 4 + } + + per_database_settings { + min_capacity = 0.25 + max_capacity = 4 + } +} + +resource "azurerm_mssql_database" "test" { + name = "acctest-db-%[2]d" + server_id = azurerm_mssql_server.test.id + elastic_pool_id = azurerm_mssql_elasticpool.test.id + sku_name = "ElasticPool" +} +`, r.template(data), data.RandomInteger) +}