From 06f966b20752cfccefe6d49baff0d5563ed0ce8a Mon Sep 17 00:00:00 2001 From: Vladimir Lazarenko Date: Tue, 12 Oct 2021 20:56:33 +0200 Subject: [PATCH] Check whether Free tier really works --- .../security_center_workspace_resource.go | 34 ------------------- ...security_center_workspace_resource_test.go | 4 +-- 2 files changed, 2 insertions(+), 36 deletions(-) diff --git a/internal/services/securitycenter/security_center_workspace_resource.go b/internal/services/securitycenter/security_center_workspace_resource.go index 2ee77282ba0e..ba04b80ff0aa 100644 --- a/internal/services/securitycenter/security_center_workspace_resource.go +++ b/internal/services/securitycenter/security_center_workspace_resource.go @@ -1,7 +1,6 @@ package securitycenter import ( - "context" "fmt" "log" "time" @@ -55,7 +54,6 @@ func resourceSecurityCenterWorkspace() *pluginsdk.Resource { } func resourceSecurityCenterWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - priceClient := meta.(*clients.Client).SecurityCenter.PricingClient client := meta.(*clients.Client).SecurityCenter.WorkspaceClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -75,17 +73,6 @@ func resourceSecurityCenterWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta } } - // get pricing tier, workspace can only be configured when tier is not Free. - // API does not error, it just doesn't set the workspace scope - isPricingStandard, err := isPricingStandard(ctx, priceClient) - if err != nil { - return fmt.Errorf("Checking Security Center Subscription pricing tier %v", err) - } - - if !isPricingStandard { - return fmt.Errorf("Security Center Subscription workspace cannot be set when pricing tier is `Free`") - } - workspaceID, err := parse.LogAnalyticsWorkspaceID(d.Get("workspace_id").(string)) if err != nil { return err @@ -145,27 +132,6 @@ func resourceSecurityCenterWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta return resourceSecurityCenterWorkspaceRead(d, meta) } -func isPricingStandard(ctx context.Context, priceClient *security.PricingsClient) (bool, error) { - prices, err := priceClient.List(ctx) - if err != nil { - return false, fmt.Errorf("Listing Security Center Subscription pricing: %+v", err) - } - - if prices.Value != nil { - for _, resourcePrice := range *prices.Value { - if resourcePrice.PricingProperties == nil { - return false, fmt.Errorf("%v Security Center Subscription pricing properties is nil", *resourcePrice.Type) - } - - if resourcePrice.PricingProperties.PricingTier == security.PricingTierStandard { - return true, nil - } - } - } - - return false, nil -} - func resourceSecurityCenterWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).SecurityCenter.WorkspaceClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) diff --git a/internal/services/securitycenter/security_center_workspace_resource_test.go b/internal/services/securitycenter/security_center_workspace_resource_test.go index e76f528fb544..885c6841e3d4 100644 --- a/internal/services/securitycenter/security_center_workspace_resource_test.go +++ b/internal/services/securitycenter/security_center_workspace_resource_test.go @@ -108,7 +108,7 @@ provider "azurerm" { } resource "azurerm_security_center_subscription_pricing" "test" { - tier = "Standard" + tier = "Free" resource_type = "VirtualMachines" } @@ -149,7 +149,7 @@ provider "azurerm" { } resource "azurerm_security_center_subscription_pricing" "test" { - tier = "Standard" + tier = "Free" } resource "azurerm_resource_group" "test" {