-
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.
Update
azurerm_security_center_subscription_pricing
(#8549)
- Loading branch information
Showing
65 changed files
with
24,383 additions
and
11,139 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
30 changes: 30 additions & 0 deletions
30
azurerm/internal/services/securitycenter/parse/security_center_subscription_pricing.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,30 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type SecurityCenterSubscriptionPricingId struct { | ||
ResourceType string | ||
} | ||
|
||
func SecurityCenterSubscriptionPricingID(input string) (*SecurityCenterSubscriptionPricingId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse Security Center Subscription Pricing ID %q: %+v", input, err) | ||
} | ||
|
||
pricing := SecurityCenterSubscriptionPricingId{} | ||
|
||
if pricing.ResourceType, err = id.PopSegment("pricings"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &pricing, nil | ||
} |
54 changes: 54 additions & 0 deletions
54
azurerm/internal/services/securitycenter/parse/security_center_subscription_pricing_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,54 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSecurityCenterSubscriptionPricingID(t *testing.T) { | ||
testData := []struct { | ||
ResourceType string | ||
Input string | ||
Error bool | ||
Expect *SecurityCenterSubscriptionPricingId | ||
}{ | ||
{ | ||
ResourceType: "Empty", | ||
Input: "", | ||
Error: true, | ||
}, | ||
{ | ||
ResourceType: "No Pricings Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Error: true, | ||
}, | ||
{ | ||
ResourceType: "No Pricings Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/pricings/", | ||
Error: true, | ||
}, | ||
{ | ||
ResourceType: "Security Center Subscription Pricing ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/pricings/VirtualMachines", | ||
Expect: &SecurityCenterSubscriptionPricingId{ | ||
ResourceType: "VirtualMachines", | ||
}, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.ResourceType) | ||
|
||
actual, err := SecurityCenterSubscriptionPricingID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.ResourceType != v.Expect.ResourceType { | ||
t.Fatalf("Expected %q but got %q for ResourceType", v.Expect.ResourceType, actual.ResourceType) | ||
} | ||
} | ||
} |
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
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
37 changes: 37 additions & 0 deletions
37
...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,37 @@ | ||
package securitycenter | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
|
||
"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") | ||
oldId := rawState["id"].(string) | ||
newId := strings.Replace(oldId, "/default", "/VirtualMachines", 1) | ||
|
||
log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) | ||
|
||
rawState["id"] = newId | ||
|
||
return rawState, nil | ||
} |
Oops, something went wrong.