Skip to content

Commit

Permalink
azurerm_security_center_server_vulnerability_assessment - deprecate…
Browse files Browse the repository at this point in the history
… in favour of `azurerm_security_center_vm_server_vulnerability_assessment` (#15747)

Co-authored-by: tombuildsstuff <[email protected]>
  • Loading branch information
catriona-m and tombuildsstuff authored Mar 23, 2022
1 parent 4295f54 commit fbf0c92
Show file tree
Hide file tree
Showing 13 changed files with 797 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type VulnerabilityAssessmentVmId struct {
SubscriptionId string
ResourceGroup string
VirtualMachineName string
ServerVulnerabilityAssessmentName string
}

func NewVulnerabilityAssessmentVmID(subscriptionId, resourceGroup, virtualMachineName, serverVulnerabilityAssessmentName string) VulnerabilityAssessmentVmId {
return VulnerabilityAssessmentVmId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
VirtualMachineName: virtualMachineName,
ServerVulnerabilityAssessmentName: serverVulnerabilityAssessmentName,
}
}

func (id VulnerabilityAssessmentVmId) String() string {
segments := []string{
fmt.Sprintf("Server Vulnerability Assessment Name %q", id.ServerVulnerabilityAssessmentName),
fmt.Sprintf("Virtual Machine Name %q", id.VirtualMachineName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Vulnerability Assessment Vm", segmentsStr)
}

func (id VulnerabilityAssessmentVmId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachines/%s/providers/Microsoft.Security/serverVulnerabilityAssessments/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.VirtualMachineName, id.ServerVulnerabilityAssessmentName)
}

// VulnerabilityAssessmentVmID parses a VulnerabilityAssessmentVm ID into an VulnerabilityAssessmentVmId struct
func VulnerabilityAssessmentVmID(input string) (*VulnerabilityAssessmentVmId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := VulnerabilityAssessmentVmId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.VirtualMachineName, err = id.PopSegment("virtualMachines"); err != nil {
return nil, err
}
if resourceId.ServerVulnerabilityAssessmentName, err = id.PopSegment("serverVulnerabilityAssessments"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.Id = VulnerabilityAssessmentVmId{}

func TestVulnerabilityAssessmentVmIDFormatter(t *testing.T) {
actual := NewVulnerabilityAssessmentVmID("12345678-1234-9876-4563-123456789012", "resGroup1", "vm-name1", "default1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/vm-name1/providers/Microsoft.Security/serverVulnerabilityAssessments/default1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestVulnerabilityAssessmentVmID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *VulnerabilityAssessmentVmId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing VirtualMachineName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/",
Error: true,
},

{
// missing value for VirtualMachineName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/",
Error: true,
},

{
// missing ServerVulnerabilityAssessmentName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/vm-name1/providers/Microsoft.Security/",
Error: true,
},

{
// missing value for ServerVulnerabilityAssessmentName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/vm-name1/providers/Microsoft.Security/serverVulnerabilityAssessments/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/vm-name1/providers/Microsoft.Security/serverVulnerabilityAssessments/default1",
Expected: &VulnerabilityAssessmentVmId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
VirtualMachineName: "vm-name1",
ServerVulnerabilityAssessmentName: "default1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.COMPUTE/VIRTUALMACHINES/VM-NAME1/PROVIDERS/MICROSOFT.SECURITY/SERVERVULNERABILITYASSESSMENTS/DEFAULT1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := VulnerabilityAssessmentVmID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.VirtualMachineName != v.Expected.VirtualMachineName {
t.Fatalf("Expected %q but got %q for VirtualMachineName", v.Expected.VirtualMachineName, actual.VirtualMachineName)
}
if actual.ServerVulnerabilityAssessmentName != v.Expected.ServerVulnerabilityAssessmentName {
t.Fatalf("Expected %q but got %q for ServerVulnerabilityAssessmentName", v.Expected.ServerVulnerabilityAssessmentName, actual.ServerVulnerabilityAssessmentName)
}
}
}
25 changes: 13 additions & 12 deletions internal/services/securitycenter/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_advanced_threat_protection": resourceAdvancedThreatProtection(),
"azurerm_iot_security_device_group": resourceIotSecurityDeviceGroup(),
"azurerm_iot_security_solution": resourceIotSecuritySolution(),
"azurerm_security_center_assessment": resourceSecurityCenterAssessment(),
"azurerm_security_center_assessment_policy": resourceArmSecurityCenterAssessmentPolicy(),
"azurerm_security_center_contact": resourceSecurityCenterContact(),
"azurerm_security_center_setting": resourceSecurityCenterSetting(),
"azurerm_security_center_subscription_pricing": resourceSecurityCenterSubscriptionPricing(),
"azurerm_security_center_workspace": resourceSecurityCenterWorkspace(),
"azurerm_security_center_automation": resourceSecurityCenterAutomation(),
"azurerm_security_center_auto_provisioning": resourceSecurityCenterAutoProvisioning(),
"azurerm_security_center_server_vulnerability_assessment": resourceServerVulnerabilityAssessment(),
"azurerm_advanced_threat_protection": resourceAdvancedThreatProtection(),
"azurerm_iot_security_device_group": resourceIotSecurityDeviceGroup(),
"azurerm_iot_security_solution": resourceIotSecuritySolution(),
"azurerm_security_center_assessment": resourceSecurityCenterAssessment(),
"azurerm_security_center_assessment_policy": resourceArmSecurityCenterAssessmentPolicy(),
"azurerm_security_center_contact": resourceSecurityCenterContact(),
"azurerm_security_center_setting": resourceSecurityCenterSetting(),
"azurerm_security_center_subscription_pricing": resourceSecurityCenterSubscriptionPricing(),
"azurerm_security_center_workspace": resourceSecurityCenterWorkspace(),
"azurerm_security_center_automation": resourceSecurityCenterAutomation(),
"azurerm_security_center_auto_provisioning": resourceSecurityCenterAutoProvisioning(),
"azurerm_security_center_server_vulnerability_assessment": resourceServerVulnerabilityAssessment(),
"azurerm_security_center_server_vulnerability_assessment_virtual_machine": resourceServerVulnerabilityAssessmentVirtualMachine(),
}
}
2 changes: 2 additions & 0 deletions internal/services/securitycenter/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ package securitycenter
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AssessmentMetadata -id=/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/assessmentMetadata/metadata1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AutoProvisioningSetting -id=/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/autoProvisioningSettings/default -rewrite=true
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=IotSecuritySolution -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Security/IoTSecuritySolutions/solution1

//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VulnerabilityAssessmentVm -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/vm-name1/providers/Microsoft.Security/serverVulnerabilityAssessments/default1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const (
hybridMachineProvider = "Microsoft.HybridCompute"
)

// TODO: 3.0 - split this into two resources for VM and HybridVM
func resourceServerVulnerabilityAssessment() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceServerVulnerabilityAssessmentCreate,
Expand All @@ -42,6 +41,8 @@ func resourceServerVulnerabilityAssessment() *pluginsdk.Resource {
Delete: pluginsdk.DefaultTimeout(10 * time.Minute),
},

DeprecationMessage: `This resource has been deprecated in favour of the 'azurerm_security_center_vm_server_vulnerability_assessment' resource and will be removed in v4.0 of the AzureRM Provider`,

Schema: map[string]*pluginsdk.Schema{
"virtual_machine_id": {
Type: pluginsdk.TypeString,
Expand Down
Loading

0 comments on commit fbf0c92

Please sign in to comment.