diff --git a/internal/services/securitycenter/client/client.go b/internal/services/securitycenter/client/client.go index 978480e62011..027506f85948 100644 --- a/internal/services/securitycenter/client/client.go +++ b/internal/services/securitycenter/client/client.go @@ -10,23 +10,25 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/security/2022-05-01/settings" "github.com/hashicorp/go-azure-sdk/resource-manager/security/2022-12-01-preview/defenderforstorage" pricings_v2023_01_01 "github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-01-01/pricings" + "github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) type Client struct { - AssessmentsClient *security.AssessmentsClient - AssessmentsMetadataClient *assessmentsmetadata.AssessmentsMetadataClient - ContactsClient *security.ContactsClient - DeviceSecurityGroupsClient *security.DeviceSecurityGroupsClient - IotSecuritySolutionClient *security.IotSecuritySolutionClient - PricingClient *pricings_v2023_01_01.PricingsClient - WorkspaceClient *security.WorkspaceSettingsClient - AdvancedThreatProtectionClient *security.AdvancedThreatProtectionClient - AutoProvisioningClient *security.AutoProvisioningSettingsClient - SettingClient *settings.SettingsClient - AutomationsClient *automations.AutomationsClient - ServerVulnerabilityAssessmentClient *security.ServerVulnerabilityAssessmentClient - DefenderForStorageClient *defenderforstorage.DefenderForStorageClient + AssessmentsClient *security.AssessmentsClient + AssessmentsMetadataClient *assessmentsmetadata.AssessmentsMetadataClient + ContactsClient *security.ContactsClient + DeviceSecurityGroupsClient *security.DeviceSecurityGroupsClient + IotSecuritySolutionClient *security.IotSecuritySolutionClient + PricingClient *pricings_v2023_01_01.PricingsClient + WorkspaceClient *security.WorkspaceSettingsClient + AdvancedThreatProtectionClient *security.AdvancedThreatProtectionClient + AutoProvisioningClient *security.AutoProvisioningSettingsClient + SettingClient *settings.SettingsClient + AutomationsClient *automations.AutomationsClient + ServerVulnerabilityAssessmentClient *security.ServerVulnerabilityAssessmentClient + ServerVulnerabilityAssessmentSettingClient *servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient + DefenderForStorageClient *defenderforstorage.DefenderForStorageClient } func NewClient(o *common.ClientOptions) *Client { @@ -68,22 +70,26 @@ func NewClient(o *common.ClientOptions) *Client { ServerVulnerabilityAssessmentClient := security.NewServerVulnerabilityAssessmentClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId, ascLocation) o.ConfigureClient(&ServerVulnerabilityAssessmentClient.Client, o.ResourceManagerAuthorizer) + ServerVulnerabilityAssessmentSettingClient := servervulnerabilityassessmentssettings.NewServerVulnerabilityAssessmentsSettingsClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&ServerVulnerabilityAssessmentSettingClient.Client, o.ResourceManagerAuthorizer) + DefenderForStorageClient := defenderforstorage.NewDefenderForStorageClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&DefenderForStorageClient.Client, o.ResourceManagerAuthorizer) return &Client{ - AssessmentsClient: &AssessmentsClient, - AssessmentsMetadataClient: &AssessmentsMetadataClient, - ContactsClient: &ContactsClient, - DeviceSecurityGroupsClient: &DeviceSecurityGroupsClient, - IotSecuritySolutionClient: &IotSecuritySolutionClient, - PricingClient: &PricingClient, - WorkspaceClient: &WorkspaceClient, - AdvancedThreatProtectionClient: &AdvancedThreatProtectionClient, - AutoProvisioningClient: &AutoProvisioningClient, - SettingClient: &SettingClient, - AutomationsClient: &AutomationsClient, - ServerVulnerabilityAssessmentClient: &ServerVulnerabilityAssessmentClient, - DefenderForStorageClient: &DefenderForStorageClient, + AssessmentsClient: &AssessmentsClient, + AssessmentsMetadataClient: &AssessmentsMetadataClient, + ContactsClient: &ContactsClient, + DeviceSecurityGroupsClient: &DeviceSecurityGroupsClient, + IotSecuritySolutionClient: &IotSecuritySolutionClient, + PricingClient: &PricingClient, + WorkspaceClient: &WorkspaceClient, + AdvancedThreatProtectionClient: &AdvancedThreatProtectionClient, + AutoProvisioningClient: &AutoProvisioningClient, + SettingClient: &SettingClient, + AutomationsClient: &AutomationsClient, + ServerVulnerabilityAssessmentClient: &ServerVulnerabilityAssessmentClient, + ServerVulnerabilityAssessmentSettingClient: &ServerVulnerabilityAssessmentSettingClient, + DefenderForStorageClient: &DefenderForStorageClient, } } diff --git a/internal/services/securitycenter/parse/vulnerability_assessments_setting.go b/internal/services/securitycenter/parse/vulnerability_assessments_setting.go new file mode 100644 index 000000000000..79d0a54d5d34 --- /dev/null +++ b/internal/services/securitycenter/parse/vulnerability_assessments_setting.go @@ -0,0 +1,64 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +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 VulnerabilityAssessmentsSettingId struct { + SubscriptionId string + ServerVulnerabilityAssessmentsSettingName string +} + +func NewVulnerabilityAssessmentsSettingID(subscriptionId, serverVulnerabilityAssessmentsSettingName string) VulnerabilityAssessmentsSettingId { + return VulnerabilityAssessmentsSettingId{ + SubscriptionId: subscriptionId, + ServerVulnerabilityAssessmentsSettingName: serverVulnerabilityAssessmentsSettingName, + } +} + +func (id VulnerabilityAssessmentsSettingId) String() string { + segments := []string{ + fmt.Sprintf("Server Vulnerability Assessments Setting Name %q", id.ServerVulnerabilityAssessmentsSettingName), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Vulnerability Assessments Setting", segmentsStr) +} + +func (id VulnerabilityAssessmentsSettingId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ServerVulnerabilityAssessmentsSettingName) +} + +// VulnerabilityAssessmentsSettingID parses a VulnerabilityAssessmentsSetting ID into an VulnerabilityAssessmentsSettingId struct +func VulnerabilityAssessmentsSettingID(input string) (*VulnerabilityAssessmentsSettingId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("parsing %q as an VulnerabilityAssessmentsSetting ID: %+v", input, err) + } + + resourceId := VulnerabilityAssessmentsSettingId{ + SubscriptionId: id.SubscriptionID, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ServerVulnerabilityAssessmentsSettingName, err = id.PopSegment("serverVulnerabilityAssessmentsSettings"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/internal/services/securitycenter/parse/vulnerability_assessments_setting_test.go b/internal/services/securitycenter/parse/vulnerability_assessments_setting_test.go new file mode 100644 index 000000000000..7e082f069c0b --- /dev/null +++ b/internal/services/securitycenter/parse/vulnerability_assessments_setting_test.go @@ -0,0 +1,99 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +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 = VulnerabilityAssessmentsSettingId{} + +func TestVulnerabilityAssessmentsSettingIDFormatter(t *testing.T) { + actual := NewVulnerabilityAssessmentsSettingID("12345678-1234-9876-4563-123456789012", "AzureServersSetting").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/AzureServersSetting" + if actual != expected { + t.Fatalf("Expected %q but got %q", expected, actual) + } +} + +func TestVulnerabilityAssessmentsSettingID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VulnerabilityAssessmentsSettingId + }{ + + { + // empty + Input: "", + Error: true, + }, + + { + // missing SubscriptionId + Input: "/", + Error: true, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Error: true, + }, + + { + // missing ServerVulnerabilityAssessmentsSettingName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/", + Error: true, + }, + + { + // missing value for ServerVulnerabilityAssessmentsSettingName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/AzureServersSetting", + Expected: &VulnerabilityAssessmentsSettingId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ServerVulnerabilityAssessmentsSettingName: "AzureServersSetting", + }, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/PROVIDERS/MICROSOFT.SECURITY/SERVERVULNERABILITYASSESSMENTSSETTINGS/AZURESERVERSSETTING", + Error: true, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := VulnerabilityAssessmentsSettingID(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.ServerVulnerabilityAssessmentsSettingName != v.Expected.ServerVulnerabilityAssessmentsSettingName { + t.Fatalf("Expected %q but got %q for ServerVulnerabilityAssessmentsSettingName", v.Expected.ServerVulnerabilityAssessmentsSettingName, actual.ServerVulnerabilityAssessmentsSettingName) + } + } +} diff --git a/internal/services/securitycenter/registration.go b/internal/services/securitycenter/registration.go index 5122e90012f8..15389132a506 100644 --- a/internal/services/securitycenter/registration.go +++ b/internal/services/securitycenter/registration.go @@ -49,6 +49,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_security_center_automation": resourceSecurityCenterAutomation(), "azurerm_security_center_auto_provisioning": resourceSecurityCenterAutoProvisioning(), "azurerm_security_center_server_vulnerability_assessment": resourceServerVulnerabilityAssessment(), + "azurerm_security_center_server_vulnerability_assessments_setting": resourceSecurityCenterServerVulnerabilityAssessmentsSetting(), "azurerm_security_center_server_vulnerability_assessment_virtual_machine": resourceServerVulnerabilityAssessmentVirtualMachine(), } } diff --git a/internal/services/securitycenter/resourceids.go b/internal/services/securitycenter/resourceids.go index 715a80f28b81..fd70042270da 100644 --- a/internal/services/securitycenter/resourceids.go +++ b/internal/services/securitycenter/resourceids.go @@ -14,3 +14,4 @@ package securitycenter //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 -rewrite=true //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 +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VulnerabilityAssessmentsSetting -id=/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/AzureServersSetting diff --git a/internal/services/securitycenter/security_center_server_vulnerability_assessments_setting_resource.go b/internal/services/securitycenter/security_center_server_vulnerability_assessments_setting_resource.go new file mode 100644 index 000000000000..c11fe29d4597 --- /dev/null +++ b/internal/services/securitycenter/security_center_server_vulnerability_assessments_setting_resource.go @@ -0,0 +1,135 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package securitycenter + +import ( + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/securitycenter/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +func resourceSecurityCenterServerVulnerabilityAssessmentsSetting() *pluginsdk.Resource { + + return &pluginsdk.Resource{ + Create: resourceSecurityCenterServerVulnerabilityAssessmentsSettingCreateOrUpdate, + Read: resourceSecurityCenterServerVulnerabilityAssessmentsSettingRead, + Update: resourceSecurityCenterServerVulnerabilityAssessmentsSettingCreateOrUpdate, + Delete: resourceSecurityCenterServerVulnerabilityAssessmentsSettingDelete, + + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { + _, err := parse.VulnerabilityAssessmentsSettingID(id) + return err + }), + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(10 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(10 * time.Minute), + Delete: pluginsdk.DefaultTimeout(10 * time.Minute), + }, + + Schema: map[string]*pluginsdk.Schema{ + "vulnerability_assessment_provider": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(servervulnerabilityassessmentssettings.PossibleValuesForServerVulnerabilityAssessmentsAzureSettingSelectedProvider(), false), + }, + }, + } +} + +func resourceSecurityCenterServerVulnerabilityAssessmentsSettingCreateOrUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).SecurityCenter.ServerVulnerabilityAssessmentSettingClient + subscriptionId := commonids.NewSubscriptionID(meta.(*clients.Client).Account.SubscriptionId) + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id := parse.NewVulnerabilityAssessmentsSettingID(subscriptionId.SubscriptionId, "AzureServersSetting") + + if d.IsNewResource() { + existing, err := client.Get(ctx, subscriptionId) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %v", id, err) + } + + if existing.Model != nil { + if azureServersSetting, ok := (*existing.Model).(servervulnerabilityassessmentssettings.AzureServersSetting); ok && azureServersSetting.Properties != nil && azureServersSetting.Properties.SelectedProvider != "" { + return tf.ImportAsExistsError("azurerm_security_center_server_vulnerability_assessments_setting", id.ID()) + } + } + } + } + + setting := servervulnerabilityassessmentssettings.AzureServersSetting{ + Type: utils.String("AzureServersSetting"), + Name: utils.String("AzureServersSetting"), + Properties: &servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsAzureSettingProperties{ + SelectedProvider: servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsAzureSettingSelectedProvider(d.Get("vulnerability_assessment_provider").(string)), + }, + } + + if _, err := client.CreateOrUpdate(ctx, subscriptionId, setting); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + d.SetId(id.ID()) + return resourceSecurityCenterServerVulnerabilityAssessmentsSettingRead(d, meta) +} + +func resourceSecurityCenterServerVulnerabilityAssessmentsSettingRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).SecurityCenter.ServerVulnerabilityAssessmentSettingClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.VulnerabilityAssessmentsSettingID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, commonids.NewSubscriptionID(id.SubscriptionId)) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + d.SetId("") + return nil + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + if resp.Model != nil { + if azureServersSetting, ok := (*resp.Model).(servervulnerabilityassessmentssettings.AzureServersSetting); ok && azureServersSetting.Properties != nil { + d.Set("vulnerability_assessment_provider", azureServersSetting.Properties.SelectedProvider) + } + } + + return nil +} + +func resourceSecurityCenterServerVulnerabilityAssessmentsSettingDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).SecurityCenter.ServerVulnerabilityAssessmentSettingClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := parse.VulnerabilityAssessmentsSettingID(d.Id()) + if err != nil { + return err + } + + if _, err := client.Delete(ctx, commonids.NewSubscriptionID(id.SubscriptionId)); err != nil { + return fmt.Errorf("disabling %s: %+v", id, err) + } + + return nil +} diff --git a/internal/services/securitycenter/security_center_server_vulnerability_assessments_setting_resource_test.go b/internal/services/securitycenter/security_center_server_vulnerability_assessments_setting_resource_test.go new file mode 100644 index 000000000000..71aa84c74336 --- /dev/null +++ b/internal/services/securitycenter/security_center_server_vulnerability_assessments_setting_resource_test.go @@ -0,0 +1,84 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package securitycenter_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/securitycenter/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type SecurityCenterServerVulnerabilityAssessmentsSettingResource struct{} + +func TestAccSecurityCenterVulnerabilityAssessmentsSetting_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_security_center_server_vulnerability_assessments_setting", "test") + r := SecurityCenterServerVulnerabilityAssessmentsSettingResource{} + + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basicCfg("MdeTvm"), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (SecurityCenterServerVulnerabilityAssessmentsSettingResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := parse.VulnerabilityAssessmentsSettingID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.SecurityCenter.ServerVulnerabilityAssessmentSettingClient.Get(ctx, commonids.NewSubscriptionID(id.SubscriptionId)) + if err != nil { + return nil, fmt.Errorf("checking for presence of existing %s: %v", id, err) + } + + if resp.Model == nil { + return utils.Bool(false), nil + } + + if azureServersSetting, ok := (*resp.Model).(servervulnerabilityassessmentssettings.AzureServersSetting); ok { + if azureServersSetting.Properties == nil { + return utils.Bool(false), nil + } + if azureServersSetting.Properties.SelectedProvider != "" { + return utils.Bool(true), nil + } + } + + return utils.Bool(false), nil +} + +func (SecurityCenterServerVulnerabilityAssessmentsSettingResource) basicCfg(providerName string) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_security_center_subscription_pricing" "test" { + tier = "Standard" + resource_type = "VirtualMachines" + subplan = "P2" +} + + +resource "azurerm_security_center_server_vulnerability_assessments_setting" "test" { + vulnerability_assessment_provider = "%s" + + depends_on = [azurerm_security_center_subscription_pricing.test] +} +`, providerName) +} diff --git a/internal/services/securitycenter/validate/vulnerability_assessments_setting_id.go b/internal/services/securitycenter/validate/vulnerability_assessments_setting_id.go new file mode 100644 index 000000000000..07421991ea20 --- /dev/null +++ b/internal/services/securitycenter/validate/vulnerability_assessments_setting_id.go @@ -0,0 +1,26 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/securitycenter/parse" +) + +func VulnerabilityAssessmentsSettingID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.VulnerabilityAssessmentsSettingID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/securitycenter/validate/vulnerability_assessments_setting_id_test.go b/internal/services/securitycenter/validate/vulnerability_assessments_setting_id_test.go new file mode 100644 index 000000000000..f314d40341f3 --- /dev/null +++ b/internal/services/securitycenter/validate/vulnerability_assessments_setting_id_test.go @@ -0,0 +1,67 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestVulnerabilityAssessmentsSettingID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ServerVulnerabilityAssessmentsSettingName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/", + Valid: false, + }, + + { + // missing value for ServerVulnerabilityAssessmentsSettingName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/AzureServersSetting", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/PROVIDERS/MICROSOFT.SECURITY/SERVERVULNERABILITYASSESSMENTSSETTINGS/AZURESERVERSSETTING", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := VulnerabilityAssessmentsSettingID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/README.md new file mode 100644 index 000000000000..a4c6cce6649c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings` Documentation + +The `servervulnerabilityassessmentssettings` SDK allows for interaction with the Azure Resource Manager Service `security` (API Version `2023-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings" +``` + + +### Client Initialization + +```go +client := servervulnerabilityassessmentssettings.NewServerVulnerabilityAssessmentsSettingsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsSettingsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := servervulnerabilityassessmentssettings.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSetting{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsSettingsClient.Delete` + +```go +ctx := context.TODO() +id := servervulnerabilityassessmentssettings.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.Delete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsSettingsClient.Get` + +```go +ctx := context.TODO() +id := servervulnerabilityassessmentssettings.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ServerVulnerabilityAssessmentsSettingsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := servervulnerabilityassessmentssettings.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/client.go new file mode 100644 index 000000000000..b251c73c5147 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/client.go @@ -0,0 +1,18 @@ +package servervulnerabilityassessmentssettings + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentsSettingsClient struct { + Client autorest.Client + baseUri string +} + +func NewServerVulnerabilityAssessmentsSettingsClientWithBaseURI(endpoint string) ServerVulnerabilityAssessmentsSettingsClient { + return ServerVulnerabilityAssessmentsSettingsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/constants.go new file mode 100644 index 000000000000..f3ee7ed233d6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/constants.go @@ -0,0 +1,56 @@ +package servervulnerabilityassessmentssettings + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentsAzureSettingSelectedProvider string + +const ( + ServerVulnerabilityAssessmentsAzureSettingSelectedProviderMdeTVM ServerVulnerabilityAssessmentsAzureSettingSelectedProvider = "MdeTvm" +) + +func PossibleValuesForServerVulnerabilityAssessmentsAzureSettingSelectedProvider() []string { + return []string{ + string(ServerVulnerabilityAssessmentsAzureSettingSelectedProviderMdeTVM), + } +} + +func parseServerVulnerabilityAssessmentsAzureSettingSelectedProvider(input string) (*ServerVulnerabilityAssessmentsAzureSettingSelectedProvider, error) { + vals := map[string]ServerVulnerabilityAssessmentsAzureSettingSelectedProvider{ + "mdetvm": ServerVulnerabilityAssessmentsAzureSettingSelectedProviderMdeTVM, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerVulnerabilityAssessmentsAzureSettingSelectedProvider(input) + return &out, nil +} + +type ServerVulnerabilityAssessmentsSettingKind string + +const ( + ServerVulnerabilityAssessmentsSettingKindAzureServersSetting ServerVulnerabilityAssessmentsSettingKind = "AzureServersSetting" +) + +func PossibleValuesForServerVulnerabilityAssessmentsSettingKind() []string { + return []string{ + string(ServerVulnerabilityAssessmentsSettingKindAzureServersSetting), + } +} + +func parseServerVulnerabilityAssessmentsSettingKind(input string) (*ServerVulnerabilityAssessmentsSettingKind, error) { + vals := map[string]ServerVulnerabilityAssessmentsSettingKind{ + "azureserverssetting": ServerVulnerabilityAssessmentsSettingKindAzureServersSetting, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ServerVulnerabilityAssessmentsSettingKind(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_createorupdate_autorest.go new file mode 100644 index 000000000000..b50145aa367d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_createorupdate_autorest.go @@ -0,0 +1,80 @@ +package servervulnerabilityassessmentssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ServerVulnerabilityAssessmentsSetting +} + +// CreateOrUpdate ... +func (c ServerVulnerabilityAssessmentsSettingsClient) CreateOrUpdate(ctx context.Context, id commonids.SubscriptionId, input ServerVulnerabilityAssessmentsSetting) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "CreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c ServerVulnerabilityAssessmentsSettingsClient) preparerForCreateOrUpdate(ctx context.Context, id commonids.SubscriptionId, input ServerVulnerabilityAssessmentsSetting) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/azureServersSetting", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForCreateOrUpdate handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (c ServerVulnerabilityAssessmentsSettingsClient) responderForCreateOrUpdate(resp *http.Response) (result CreateOrUpdateOperationResponse, err error) { + var respObj json.RawMessage + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusCreated, http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + if err != nil { + return + } + model, err := unmarshalServerVulnerabilityAssessmentsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_delete_autorest.go new file mode 100644 index 000000000000..b0c96d0e2b1a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_delete_autorest.go @@ -0,0 +1,68 @@ +package servervulnerabilityassessmentssettings + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response +} + +// Delete ... +func (c ServerVulnerabilityAssessmentsSettingsClient) Delete(ctx context.Context, id commonids.SubscriptionId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "Delete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "Delete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDelete prepares the Delete request. +func (c ServerVulnerabilityAssessmentsSettingsClient) preparerForDelete(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/azureServersSetting", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDelete handles the response to the Delete request. The method always +// closes the http.Response Body. +func (c ServerVulnerabilityAssessmentsSettingsClient) responderForDelete(resp *http.Response) (result DeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_get_autorest.go new file mode 100644 index 000000000000..173f27a4a7e0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_get_autorest.go @@ -0,0 +1,79 @@ +package servervulnerabilityassessmentssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *ServerVulnerabilityAssessmentsSetting +} + +// Get ... +func (c ServerVulnerabilityAssessmentsSettingsClient) Get(ctx context.Context, id commonids.SubscriptionId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c ServerVulnerabilityAssessmentsSettingsClient) preparerForGet(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/azureServersSetting", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c ServerVulnerabilityAssessmentsSettingsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + var respObj json.RawMessage + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + if err != nil { + return + } + model, err := unmarshalServerVulnerabilityAssessmentsSettingImplementation(respObj) + if err != nil { + return + } + result.Model = &model + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_listbysubscription_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_listbysubscription_autorest.go new file mode 100644 index 000000000000..e38e86f15318 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/method_listbysubscription_autorest.go @@ -0,0 +1,197 @@ +package servervulnerabilityassessmentssettings + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ServerVulnerabilityAssessmentsSetting + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListBySubscriptionOperationResponse, error) +} + +type ListBySubscriptionCompleteResult struct { + Items []ServerVulnerabilityAssessmentsSetting +} + +func (r ListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListBySubscription ... +func (c ServerVulnerabilityAssessmentsSettingsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "ListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "ListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListBySubscription prepares the ListBySubscription request. +func (c ServerVulnerabilityAssessmentsSettingsClient) preparerForListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListBySubscriptionWithNextLink prepares the ListBySubscription request with the given nextLink token. +func (c ServerVulnerabilityAssessmentsSettingsClient) preparerForListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListBySubscription handles the response to the ListBySubscription request. The method always +// closes the http.Response Body. +func (c ServerVulnerabilityAssessmentsSettingsClient) responderForListBySubscription(resp *http.Response) (result ListBySubscriptionOperationResponse, err error) { + type page struct { + Values []json.RawMessage `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + temp := make([]ServerVulnerabilityAssessmentsSetting, 0) + for i, v := range respObj.Values { + val, err := unmarshalServerVulnerabilityAssessmentsSettingImplementation(v) + if err != nil { + err = fmt.Errorf("unmarshalling item %d for ServerVulnerabilityAssessmentsSetting (%q): %+v", i, v, err) + return result, err + } + temp = append(temp, val) + } + result.Model = &temp + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "ListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "ListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "servervulnerabilityassessmentssettings.ServerVulnerabilityAssessmentsSettingsClient", "ListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListBySubscriptionComplete retrieves all of the results into a single object +func (c ServerVulnerabilityAssessmentsSettingsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, ServerVulnerabilityAssessmentsSettingOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ServerVulnerabilityAssessmentsSettingsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ServerVulnerabilityAssessmentsSettingOperationPredicate) (resp ListBySubscriptionCompleteResult, err error) { + items := make([]ServerVulnerabilityAssessmentsSetting, 0) + + page, err := c.ListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_azureserverssetting.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_azureserverssetting.go new file mode 100644 index 000000000000..5dddb739adfd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_azureserverssetting.go @@ -0,0 +1,47 @@ +package servervulnerabilityassessmentssettings + +import ( + "encoding/json" + "fmt" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ ServerVulnerabilityAssessmentsSetting = AzureServersSetting{} + +type AzureServersSetting struct { + Properties *ServerVulnerabilityAssessmentsAzureSettingProperties `json:"properties,omitempty"` + + // Fields inherited from ServerVulnerabilityAssessmentsSetting + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} + +var _ json.Marshaler = AzureServersSetting{} + +func (s AzureServersSetting) MarshalJSON() ([]byte, error) { + type wrapper AzureServersSetting + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling AzureServersSetting: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling AzureServersSetting: %+v", err) + } + decoded["kind"] = "AzureServersSetting" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling AzureServersSetting: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_servervulnerabilityassessmentsazuresettingproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_servervulnerabilityassessmentsazuresettingproperties.go new file mode 100644 index 000000000000..135cbe49088e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_servervulnerabilityassessmentsazuresettingproperties.go @@ -0,0 +1,8 @@ +package servervulnerabilityassessmentssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentsAzureSettingProperties struct { + SelectedProvider ServerVulnerabilityAssessmentsAzureSettingSelectedProvider `json:"selectedProvider"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_servervulnerabilityassessmentssetting.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_servervulnerabilityassessmentssetting.go new file mode 100644 index 000000000000..fce0f0509da7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/model_servervulnerabilityassessmentssetting.go @@ -0,0 +1,53 @@ +package servervulnerabilityassessmentssettings + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentsSetting interface { +} + +// RawServerVulnerabilityAssessmentsSettingImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawServerVulnerabilityAssessmentsSettingImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalServerVulnerabilityAssessmentsSettingImplementation(input []byte) (ServerVulnerabilityAssessmentsSetting, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling ServerVulnerabilityAssessmentsSetting into map[string]interface: %+v", err) + } + + value, ok := temp["kind"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "AzureServersSetting") { + var out AzureServersSetting + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into AzureServersSetting: %+v", err) + } + return out, nil + } + + out := RawServerVulnerabilityAssessmentsSettingImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/predicates.go new file mode 100644 index 000000000000..0d4a34ff0a7e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/predicates.go @@ -0,0 +1,12 @@ +package servervulnerabilityassessmentssettings + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ServerVulnerabilityAssessmentsSettingOperationPredicate struct { +} + +func (p ServerVulnerabilityAssessmentsSettingOperationPredicate) Matches(input ServerVulnerabilityAssessmentsSetting) bool { + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/version.go new file mode 100644 index 000000000000..3a55f7185fff --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings/version.go @@ -0,0 +1,12 @@ +package servervulnerabilityassessmentssettings + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-05-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/servervulnerabilityassessmentssettings/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a03179d594e5..41d1c25b1ac9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -888,6 +888,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/security/2021-06-01/assessmen github.com/hashicorp/go-azure-sdk/resource-manager/security/2022-05-01/settings github.com/hashicorp/go-azure-sdk/resource-manager/security/2022-12-01-preview/defenderforstorage github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-01-01/pricings +github.com/hashicorp/go-azure-sdk/resource-manager/security/2023-05-01/servervulnerabilityassessmentssettings github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/alertrules github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/automationrules github.com/hashicorp/go-azure-sdk/resource-manager/securityinsights/2022-10-01-preview/metadata diff --git a/website/docs/r/security_center_server_vulnerability_assessments_setting.html.markdown b/website/docs/r/security_center_server_vulnerability_assessments_setting.html.markdown new file mode 100644 index 000000000000..5caadaf6b10f --- /dev/null +++ b/website/docs/r/security_center_server_vulnerability_assessments_setting.html.markdown @@ -0,0 +1,52 @@ +--- +subcategory: "Security Center" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_security_center_server_vulnerability_assessments_setting" +description: |- + Manages the Server Vulnerability Assesments Setting for Azure Security Center. +--- + +# azurerm_security_center_server_vulnerability_assessments_setting + +Manages the Server Vulnerability Assesments Setting for Azure Security Center. + +~> **NOTE:** This resource requires the `Owner` permission on the Subscription. + +~> **NOTE:** Deletion of this resource disables the setting. + +## Example Usage + +```hcl +resource "azurerm_security_center_server_vulnerability_assessments_setting" "example" { + vulnerability_assessment_provider = "MdeTvm" +} +``` + +## Argument Reference + +The following arguments are supported: + +- `vulnerability_assessment_provider` - (Required) The vulnerability assesment provider to use. The only possible values is `MdeTvm`. Changing this forces a new resource to be created. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +- `id` - The server vulnerability assessments setting id. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +- `create` - (Defaults to 10 minutes) Used when creating the Security Center Setting. +- `update` - (Defaults to 10 minutes) Used when updating the Security Center Setting. +- `read` - (Defaults to 5 minutes) Used when retrieving the Security Center Setting. +- `delete` - (Defaults to 10 minutes) Used when deleting the Security Center Setting. + +## Import + +The setting can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_security_center_server_vulnerability_assessments_setting.example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Security/serverVulnerabilityAssessmentsSettings/AzureServersSetting +```