From 84e12a80cf559a8596719d4311999a61a96012f6 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 22 Oct 2024 09:56:55 +0200 Subject: [PATCH 1/3] correctly type assert additional properties for security center subscription pricings --- ...ty_center_subscription_pricing_resource.go | 12 ++++-- ...nter_subscription_pricing_resource_test.go | 40 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/internal/services/securitycenter/security_center_subscription_pricing_resource.go b/internal/services/securitycenter/security_center_subscription_pricing_resource.go index d141bcf97265..4f1581d1bb8f 100644 --- a/internal/services/securitycenter/security_center_subscription_pricing_resource.go +++ b/internal/services/securitycenter/security_center_subscription_pricing_resource.go @@ -290,10 +290,16 @@ func expandSecurityCenterSubscriptionPricingExtensions(inputList []interface{}, isEnabled = pricings_v2023_01_01.IsEnabledTrue } output := pricings_v2023_01_01.Extension{ - Name: extensionName, - IsEnabled: isEnabled, - AdditionalExtensionProperties: pointer.To(extensionProperties), + Name: extensionName, + IsEnabled: isEnabled, } + + if vAdditional, ok := extensionProperties[extensionName]; ok { + props, _ := vAdditional.(*interface{}) + p := (*props).(map[string]interface{}) + output.AdditionalExtensionProperties = pointer.To(p) + } + outputList = append(outputList, output) } diff --git a/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go b/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go index cc068d58218e..0402c4eabc22 100644 --- a/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go +++ b/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go @@ -109,6 +109,21 @@ func TestAccSecurityCenterSubscriptionPricing_storageAccountSubplan(t *testing.T }) } +func TestAccSecurityCenterSubscriptionPricing_storageAccountDefender(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_security_center_subscription_pricing", "test") + r := SecurityCenterSubscriptionPricingResource{} + + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.storageAccountDefender(), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func testAccSecurityCenterSubscriptionPricing_cloudPostureExtension(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_security_center_subscription_pricing", "test") r := SecurityCenterSubscriptionPricingResource{} @@ -242,6 +257,31 @@ resource "azurerm_security_center_subscription_pricing" "test" { ` } +func (SecurityCenterSubscriptionPricingResource) storageAccountDefender() string { + return ` +provider "azurerm" { + features {} +} + +resource "azurerm_security_center_subscription_pricing" "test" { + tier = "Standard" + resource_type = "StorageAccounts" + subplan = "DefenderForStorageV2" + + extension { + additional_extension_properties = { + "CapGBPerMonthPerStorageAccount" = "5000" + } + name = "OnUploadMalwareScanning" + } + + extension { + name = "SensitiveDataDiscovery" + } +} +` +} + func (SecurityCenterSubscriptionPricingResource) cloudPostureExtension() string { return ` provider "azurerm" { From cd3f8e65709db809eb75b7ad9cc971f353f084c0 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 22 Oct 2024 11:19:05 +0200 Subject: [PATCH 2/3] run subscription pricing tests for storage sequentially --- ...ty_center_subscription_pricing_resource_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go b/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go index 0402c4eabc22..7316d38e8284 100644 --- a/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go +++ b/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go @@ -60,6 +60,16 @@ func TestAccSecurityCenterSubscriptionPricing_cloudPosture(t *testing.T) { }) } +func TestAccSecurityCenterSubscriptionPricing_storage(t *testing.T) { + // These tests will change pricing tier of cloud posture + acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ + "securityCenterSubscriptionPricing": { + "subplan": testAccSecurityCenterSubscriptionPricing_storageAccountSubplan, + "defender": testAccSecurityCenterSubscriptionPricing_storageAccountDefender, + }, + }) +} + func TestAccSecurityCenterSubscriptionPricing_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_security_center_subscription_pricing", "test") r := SecurityCenterSubscriptionPricingResource{} @@ -92,7 +102,7 @@ func TestAccSecurityCenterSubscriptionPricing_cosmosDbs(t *testing.T) { }) } -func TestAccSecurityCenterSubscriptionPricing_storageAccountSubplan(t *testing.T) { +func testAccSecurityCenterSubscriptionPricing_storageAccountSubplan(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_security_center_subscription_pricing", "test") r := SecurityCenterSubscriptionPricingResource{} @@ -109,7 +119,7 @@ func TestAccSecurityCenterSubscriptionPricing_storageAccountSubplan(t *testing.T }) } -func TestAccSecurityCenterSubscriptionPricing_storageAccountDefender(t *testing.T) { +func testAccSecurityCenterSubscriptionPricing_storageAccountDefender(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_security_center_subscription_pricing", "test") r := SecurityCenterSubscriptionPricingResource{} From e0f8111bea2d62f40d699e8948fbaade00dda54d Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 22 Oct 2024 13:47:00 +0200 Subject: [PATCH 3/3] remove irrelevant comment --- .../security_center_subscription_pricing_resource_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go b/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go index 7316d38e8284..16962b71ac43 100644 --- a/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go +++ b/internal/services/securitycenter/security_center_subscription_pricing_resource_test.go @@ -61,7 +61,6 @@ func TestAccSecurityCenterSubscriptionPricing_cloudPosture(t *testing.T) { } func TestAccSecurityCenterSubscriptionPricing_storage(t *testing.T) { - // These tests will change pricing tier of cloud posture acceptance.RunTestsInSequence(t, map[string]map[string]func(t *testing.T){ "securityCenterSubscriptionPricing": { "subplan": testAccSecurityCenterSubscriptionPricing_storageAccountSubplan,