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_mssql_elasticpool : fix license_type can't be set to null when changing from vCore to DTU model issue #23262

Merged
merged 3 commits into from
Sep 19, 2023
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
14 changes: 5 additions & 9 deletions internal/services/mssql/mssql_elasticpool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,6 @@ func resourceMsSqlElasticPoolCreateUpdate(d *pluginsdk.ResourceData, meta interf
},
}

if _, ok := d.GetOk("license_type"); ok {
if sku.Tier != nil && (*sku.Tier == "GeneralPurpose" || *sku.Tier == "BusinessCritical" || *sku.Tier == "Hyperscale") {
elasticPool.ElasticPoolProperties.LicenseType = sql.ElasticPoolLicenseType(d.Get("license_type").(string))
} else {
return fmt.Errorf("`license_type` can only be configured when `sku.0.tier` is set to `GeneralPurpose`, `Hyperscale` or `BusinessCritical`")
}
}

if d.HasChange("max_size_gb") {
if v, ok := d.GetOk("max_size_gb"); ok {
maxSizeBytes := v.(float64) * 1073741824
Expand Down Expand Up @@ -307,7 +299,11 @@ func resourceMsSqlElasticPoolRead(d *pluginsdk.ResourceData, meta interface{}) e
}
}
d.Set("zone_redundant", properties.ZoneRedundant)
d.Set("license_type", string(properties.LicenseType))
licenseType := string(sql.DatabaseLicenseTypeLicenseIncluded)
if string(properties.LicenseType) != "" {
licenseType = string(properties.LicenseType)
}
d.Set("license_type", licenseType)

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

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.noLicenseType(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.updateToStandardDTU(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.licenseType(data, "LicenseIncluded"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.updateToStandardDTU(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (MsSqlElasticPoolResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ElasticPoolID(state.ID)
if err != nil {
Expand Down Expand Up @@ -330,6 +366,10 @@ func (r MsSqlElasticPoolResource) basicVCore(data acceptance.TestData) string {
return r.templateVCore(data, "GP_Gen5", "GeneralPurpose", 4, "Gen5", 0.25, 4)
}

func (r MsSqlElasticPoolResource) updateToStandardDTU(data acceptance.TestData) string {
return r.templateUpdateToDTU(data, "StandardPool", "Standard", 50, 50, 10, 50, false)
}

func (r MsSqlElasticPoolResource) fsv2VCore(data acceptance.TestData) string {
return r.templateVCore(data, "GP_Fsv2", "GeneralPurpose", 8, "Fsv2", 0, 8)
}
Expand Down Expand Up @@ -405,6 +445,62 @@ resource "azurerm_mssql_elasticpool" "test" {
`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, maxSizeGB, databaseSettingsMin, databaseSettingsMax, zoneRedundant, configName)
}

func (MsSqlElasticPoolResource) templateUpdateToDTU(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, maxSizeGB float64, databaseSettingsMin int, databaseSettingsMax int, zoneRedundant bool) string {
configName := "SQL_Default"
if skuTier != "Basic" {
switch data.Locations.Primary {
case "westeurope":
configName = "SQL_WestEurope_DB_2"
case "francecentral":
configName = "SQL_FranceCentral_DB_1"
default:
configName = "SQL_Default"
}
}

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-dtu-%[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 = %.7[6]f
zone_redundant = %[9]t

maintenance_configuration_name = "%[10]s"

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

per_database_settings {
min_capacity = %[7]d
max_capacity = %[8]d
}
}
`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, maxSizeGB, databaseSettingsMin, databaseSettingsMax, zoneRedundant, configName)
}

func (MsSqlElasticPoolResource) templateVCore(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -528,6 +624,49 @@ resource "azurerm_mssql_elasticpool" "test" {
`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, skuFamily, databaseSettingsMin, databaseSettingsMax)
}

func (MsSqlElasticPoolResource) noLicenseType(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-dtu-%[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 = 50
zone_redundant = false

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

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

func (MsSqlElasticPoolResource) licenseType(data acceptance.TestData, licenseType string) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down Expand Up @@ -568,7 +707,6 @@ resource "azurerm_mssql_elasticpool" "test" {
min_capacity = 0
max_capacity = 4
}

}
`, data.RandomInteger, data.Locations.Primary, licenseType)
}
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/mssql_elasticpool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ The following arguments are supported:

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

-> **Note:** `license_type` can only be configured when `sku.0.tier` is set to `GeneralPurpose`, `Hyperscale` or `BusinessCritical`

---

The `sku` block supports the following:
Expand Down
Loading