-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to set security center pricing tier for a particular resource type
At the moment, only Virtual Machines are set with the security center standard or free pricing tiers when using `azurerm_security_center_subscription_pricing`. This change adds the field `resource_type`, which allows to specify the resource type for which we want to update the pricing tier. The v1 security center pricing client only allows to get the pricing tier of the default resource type (Virtual Machines) to check whether the subscription has standard or free security center pricing tier. However, a partial standard pricing tier (where one or more resource types have standar tier enabled) allows for a security center workspace to be created. This commit changes the client to v3 and checks if any resource type in the subscription has standard pricing tier enabled, and if so, it allows the creation of a security center workspace. provider
- Loading branch information
Showing
57 changed files
with
36,569 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...al/services/securitycenter/resource_arm_security_center_subscription_pricing_migration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package securitycenter | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v3.0/security" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
) | ||
|
||
func ResourceArmSecurityCenterSubscriptionPricingV0() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"tier": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(security.Free), | ||
string(security.Standard), | ||
}, false), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ResourceArmSecurityCenterSubscriptionPricingUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
log.Println("[DEBUG] Migrating ResourceType from v0 to v1 format") | ||
|
||
rawState["resource_type"] = "VirtualMachines" | ||
|
||
return rawState, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../securitycenter/tests/resource_arm_security_center_subscription_pricing_migration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter" | ||
) | ||
|
||
func TestAzureRMSecurityCenterSubscriptionPricingMigrateState(t *testing.T) { | ||
cases := map[string]struct { | ||
StateVersion int | ||
InputAttributes map[string]interface{} | ||
ExpectedResourceType string | ||
}{ | ||
"subscription_scope": { | ||
StateVersion: 0, | ||
InputAttributes: map[string]interface{}{ | ||
"tier": "Free", | ||
}, | ||
ExpectedResourceType: "VirtualMachines", | ||
}, | ||
"managementGroup_scope": { | ||
StateVersion: 0, | ||
InputAttributes: map[string]interface{}{ | ||
"tier": "Standard", | ||
}, | ||
ExpectedResourceType: "VirtualMachines", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
rawState, _ := securitycenter.ResourceArmSecurityCenterSubscriptionPricingUpgradeV0ToV1(tc.InputAttributes, nil) | ||
|
||
if rawState["resource_type"].(string) != tc.ExpectedResourceType { | ||
t.Fatalf("ResourceType migration failed, expected %q, got: %q", tc.ExpectedResourceType, rawState["resource_type"].(string)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.