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_database - threat_detection_policy.0.storage_* can now be correctly set as empty #19670

Merged
merged 4 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ func expandMsSqlServerSecurityAlertPolicy(d *pluginsdk.ResourceData) sql.Databas
if v, ok := securityAlert["retention_days"]; ok {
properties.RetentionDays = utils.Int32(int32(v.(int)))
}
if v, ok := securityAlert["storage_account_access_key"]; ok {
if v, ok := securityAlert["storage_account_access_key"]; ok && v.(string) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing this means these can no longer be removed, can we add a test removing these to confirm that works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was all good with no code changes but I added a test to confirm!

properties.StorageAccountAccessKey = utils.String(v.(string))
}
if v, ok := securityAlert["storage_endpoint"]; ok {
if v, ok := securityAlert["storage_endpoint"]; ok && v.(string) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing this means these can no longer be removed, can we add a test removing these to confirm that works?

properties.StorageEndpoint = utils.String(v.(string))
}

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 @@ -500,6 +500,26 @@ func TestAccMsSqlDatabase_threatDetectionPolicy(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.threatDetectionPolicyNoStorage(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("threat_detection_policy.#").HasValue("1"),
check.That(data.ResourceName).Key("threat_detection_policy.0.state").HasValue("Enabled"),
check.That(data.ResourceName).Key("threat_detection_policy.0.retention_days").HasValue("15"),
check.That(data.ResourceName).Key("threat_detection_policy.0.disabled_alerts.#").HasValue("1"),
check.That(data.ResourceName).Key("threat_detection_policy.0.email_account_admins").HasValue("Enabled"),
),
},
data.ImportStep("sample_name", "threat_detection_policy.0.storage_account_access_key"),
})
}

func TestAccMsSqlDatabase_updateSku(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_database", "test")
r := MsSqlDatabaseResource{}
Expand Down Expand Up @@ -1294,6 +1314,33 @@ resource "azurerm_mssql_database" "test" {
`, r.template(data), data.RandomInteger, state)
}

func (r MsSqlDatabaseResource) threatDetectionPolicyNoStorage(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
collation = "SQL_AltDiction_CP850_CI_AI"
license_type = "BasePrice"
max_size_gb = 1
sample_name = "AdventureWorksLT"
sku_name = "GP_Gen5_2"

threat_detection_policy {
retention_days = 15
state = "Enabled"
disabled_alerts = ["Sql_Injection"]
email_account_admins = "Enabled"
}

tags = {
ENV = "Test"
}
}
`, r.template(data), data.RandomInteger)
}

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