Skip to content

Commit

Permalink
azurerm_mssql_database - update nil validation for license_type (#…
Browse files Browse the repository at this point in the history
…26850)

* azurerm_mssql_database - update nil validation for license_type

* not explicitly set license to nul
  • Loading branch information
neil-yechenwei authored Aug 13, 2024
1 parent abfc47c commit abe7e8d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ func resourceMsSqlDatabaseUpdate(d *pluginsdk.ResourceData, meta interface{}) er
// Determine whether the SKU is for SQL Data Warehouse
isDwSku := strings.HasPrefix(strings.ToLower(skuName), "dw")

if strings.HasPrefix(skuName, "GP_S_") && d.Get("license_type").(string) != "" {
if strings.HasPrefix(skuName, "GP_S_") && !pluginsdk.IsExplicitlyNullInConfig(d, "license_type") {
return fmt.Errorf("serverless databases do not support license type")
}

Expand Down
47 changes: 47 additions & 0 deletions internal/services/mssql/mssql_database_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ func TestAccMsSqlDatabase_gpServerless(t *testing.T) {
})
}

func TestAccMsSqlDatabase_updateLicenseType(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_database", "test")
r := MsSqlDatabaseResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.gpWithLicenseType(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.gpServerlessWithNullLicenseType(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("license_type"),
})
}

func TestAccMsSqlDatabase_bc(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_database", "test")
r := MsSqlDatabaseResource{}
Expand Down Expand Up @@ -1226,6 +1248,31 @@ resource "azurerm_mssql_database" "test" {
`, r.template(data), data.RandomInteger)
}

func (r MsSqlDatabaseResource) gpWithLicenseType(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
resource "azurerm_mssql_database" "test" {
name = "acctest-db-%[2]d"
server_id = azurerm_mssql_server.test.id
sku_name = "GP_Gen5_2"
license_type = "LicenseIncluded"
}
`, r.template(data), data.RandomInteger)
}

func (r MsSqlDatabaseResource) gpServerlessWithNullLicenseType(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
resource "azurerm_mssql_database" "test" {
name = "acctest-db-%[2]d"
server_id = azurerm_mssql_server.test.id
sku_name = "GP_S_Gen5_2"
}
`, r.template(data), data.RandomInteger)
}

func (r MsSqlDatabaseResource) hs(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down

0 comments on commit abe7e8d

Please sign in to comment.