From 58ef1ab9afec624df016584765a2c7aa173f0570 Mon Sep 17 00:00:00 2001 From: Catriona Date: Mon, 21 Mar 2022 16:46:30 +0000 Subject: [PATCH] correct ids and docs naming --- ...assessment_arc_virtual_machine_resource.go | 28 +++------- ...erver_vulnerability_assessment_resource.go | 2 +- ...ity_assessment_virtual_machine_resource.go | 19 +------ ...ssessment_virtual_machine_resource_test.go | 11 ++-- ...ver_vulnerability_assessment.html.markdown | 51 ----------------- ...sessment_arc_virtual_machine.html.markdown | 56 +++++++++++++++++++ ..._assessment_virtual_machine.html.markdown} | 11 ++-- 7 files changed, 76 insertions(+), 102 deletions(-) delete mode 100644 website/docs/r/security_center_hybrid_vm_server_vulnerability_assessment.html.markdown create mode 100644 website/docs/r/security_center_server_vulnerability_assessment_arc_virtual_machine.html.markdown rename website/docs/r/{security_center_vm_server_vulnerability_assessment.html.markdown => security_center_server_vulnerability_assessment_virtual_machine.html.markdown} (81%) diff --git a/internal/services/securitycenter/security_center_server_vulnerability_assessment_arc_virtual_machine_resource.go b/internal/services/securitycenter/security_center_server_vulnerability_assessment_arc_virtual_machine_resource.go index b80d001610ea..49cf350523e9 100644 --- a/internal/services/securitycenter/security_center_server_vulnerability_assessment_arc_virtual_machine_resource.go +++ b/internal/services/securitycenter/security_center_server_vulnerability_assessment_arc_virtual_machine_resource.go @@ -60,25 +60,24 @@ func resourceServerVulnerabilityAssessmentArcVirtualMachineCreate(d *pluginsdk.R return err } - vulnerabilityAssessment, err := client.Get(ctx, hybridMachineId.ResourceGroup, hybridProvider, hybridType, hybridMachineId.MachineName) + id := parse.NewVulnerabilityAssessmentVmID(hybridMachineId.SubscriptionId, hybridMachineId.ResourceGroup, hybridMachineId.MachineName, "Default") + + vulnerabilityAssessment, err := client.Get(ctx, id.ResourceGroup, hybridProvider, hybridType, id.VirtualMachineName) if err != nil { if !utils.ResponseWasNotFound(vulnerabilityAssessment.Response) { - return fmt.Errorf("checking for presence of existing Advanced Threat Protection for %s: %+v", *hybridMachineId, err) + return fmt.Errorf("checking for presence of existing Advanced Threat Protection for %s: %+v", id, err) } } if vulnerabilityAssessment.ID != nil && *vulnerabilityAssessment.ID != "" { - return tf.ImportAsExistsError("azurerm_security_center_server_vulnerability_assessment_arc_virtual_machine", *vulnerabilityAssessment.ID) + return tf.ImportAsExistsError("azurerm_security_center_server_vulnerability_assessment_arc_virtual_machine", id.ID()) } - vulnerabilityAssessment, err = client.CreateOrUpdate(ctx, hybridMachineId.ResourceGroup, hybridProvider, hybridType, hybridMachineId.MachineName) + vulnerabilityAssessment, err = client.CreateOrUpdate(ctx, id.ResourceGroup, hybridProvider, hybridType, id.VirtualMachineName) if err != nil { return fmt.Errorf("create Server Vulnerability Assessment for %s: %+v", *hybridMachineId, err) } - id := parse.NewVulnerabilityAssessmentVmID(hybridMachineId.SubscriptionId, hybridMachineId.ResourceGroup, hybridMachineId.MachineName, "Default") - d.SetId(id.ID()) - timeout, _ := ctx.Deadline() stateConf := &pluginsdk.StateChangeConf{ Pending: []string{"Pending"}, @@ -92,6 +91,7 @@ func resourceServerVulnerabilityAssessmentArcVirtualMachineCreate(d *pluginsdk.R return fmt.Errorf("waiting for the completion of the creating/updating of %s: %+v", id, err) } + d.SetId(id.ID()) return resourceServerVulnerabilityAssessmentArcVirtualMachineRead(d, meta) } @@ -144,20 +144,6 @@ func resourceServerVulnerabilityAssessmentArcVirtualMachineDelete(d *pluginsdk.R return err } - // Cannot delete if still in provisioning state. Wait for it to complete. - timeout, _ := ctx.Deadline() - stateConf := &pluginsdk.StateChangeConf{ - Pending: []string{"Pending"}, - Target: []string{"Succeeded"}, - Refresh: serverVulnerabilityAssessmentArcVirtualMachineStateRefreshFunc(ctx, client, id.ResourceGroup, id.VirtualMachineName), - PollInterval: 10 * time.Second, - Timeout: time.Until(timeout), - } - - if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for the completion of the creation of %s: %+v", id, err) - } - future, err := client.Delete(ctx, id.ResourceGroup, hybridProvider, hybridType, id.VirtualMachineName) if err != nil { return fmt.Errorf("deleting Server Vulnerability Assessment %s: %v", *id, err) diff --git a/internal/services/securitycenter/security_center_server_vulnerability_assessment_resource.go b/internal/services/securitycenter/security_center_server_vulnerability_assessment_resource.go index 724688ff58ff..db2a66710bde 100644 --- a/internal/services/securitycenter/security_center_server_vulnerability_assessment_resource.go +++ b/internal/services/securitycenter/security_center_server_vulnerability_assessment_resource.go @@ -41,7 +41,7 @@ func resourceServerVulnerabilityAssessment() *pluginsdk.Resource { Delete: pluginsdk.DefaultTimeout(10 * time.Minute), }, - DeprecationMessage: `This resource has been deprecated in favour of azurerm_security_center_vm_server_vulnerability_assessment and azurerm_security_center_hybrid_vm_server_vulnerability_assessment and will be removed in v3.0 of the AzureRM Provider`, + DeprecationMessage: `This resource has been deprecated in favour of azurerm_security_center_vm_server_vulnerability_assessment and azurerm_security_center_hybrid_vm_server_vulnerability_assessment and will be removed in v4.0 of the AzureRM Provider`, Schema: map[string]*pluginsdk.Schema{ "virtual_machine_id": { diff --git a/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource.go b/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource.go index e5ef153fb8f2..81806ad0f276 100644 --- a/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource.go +++ b/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource.go @@ -59,6 +59,7 @@ func resourceServerVulnerabilityAssessmentVirtualMachineCreate(d *pluginsdk.Reso if err != nil { return err } + id := parse.NewVulnerabilityAssessmentVmID(virtualMachineId.SubscriptionId, virtualMachineId.ResourceGroup, virtualMachineId.Name, "Default") vulnerabilityAssessment, err := client.Get(ctx, virtualMachineId.ResourceGroup, computeProvider, vmType, virtualMachineId.Name) if err != nil { @@ -76,9 +77,6 @@ func resourceServerVulnerabilityAssessmentVirtualMachineCreate(d *pluginsdk.Reso return fmt.Errorf("create Server Vulnerability Assessment for %s: %+v", *virtualMachineId, err) } - id := parse.NewVulnerabilityAssessmentVmID(virtualMachineId.SubscriptionId, virtualMachineId.ResourceGroup, virtualMachineId.Name, "Default") - d.SetId(id.ID()) - timeout, _ := ctx.Deadline() stateConf := &pluginsdk.StateChangeConf{ Pending: []string{"Pending"}, @@ -92,6 +90,7 @@ func resourceServerVulnerabilityAssessmentVirtualMachineCreate(d *pluginsdk.Reso return fmt.Errorf("waiting for the completion of the creating/updating of %s: %+v", id, err) } + d.SetId(id.ID()) return resourceServerVulnerabilityAssessmentVirtualMachineRead(d, meta) } @@ -144,20 +143,6 @@ func resourceServerVulnerabilityAssessmentVirtualMachineDelete(d *pluginsdk.Reso return err } - // Cannot delete if still in provisioning state. Wait for it to complete. - timeout, _ := ctx.Deadline() - stateConf := &pluginsdk.StateChangeConf{ - Pending: []string{"Pending"}, - Target: []string{"Succeeded"}, - Refresh: serverVulnerabilityAssessmentVirtualMachineStateRefreshFunc(ctx, client, id.ResourceGroup, id.VirtualMachineName), - PollInterval: 10 * time.Second, - Timeout: time.Until(timeout), - } - - if _, err := stateConf.WaitForStateContext(ctx); err != nil { - return fmt.Errorf("waiting for the completion of the creating/updating of %s: %+v", id, err) - } - future, err := client.Delete(ctx, id.ResourceGroup, computeProvider, vmType, id.VirtualMachineName) if err != nil { return fmt.Errorf("deleting Server Vulnerability Assessment %s: %v", *id, err) diff --git a/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource_test.go b/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource_test.go index 077ec0bd191a..aba29a4dc874 100644 --- a/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource_test.go +++ b/internal/services/securitycenter/security_center_server_vulnerability_assessment_virtual_machine_resource_test.go @@ -5,10 +5,10 @@ import ( "fmt" "testing" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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" ) @@ -46,17 +46,14 @@ func TestAccServerVulnerabilityAssessmentVirtualMachine_requiresImport(t *testin } func (ServerVulnerabilityAssessmentVirtualMachineResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := azure.ParseAzureResourceID(state.ID) + id, err := parse.VulnerabilityAssessmentVmID(state.ID) if err != nil { return nil, err } - resourceGroup := id.ResourceGroup - name := id.Path["virtualMachines"] - - resp, err := clients.SecurityCenter.ServerVulnerabilityAssessmentClient.Get(ctx, resourceGroup, "Microsoft.Compute", "virtualMachines", name) + resp, err := clients.SecurityCenter.ServerVulnerabilityAssessmentClient.Get(ctx, id.ResourceGroup, "Microsoft.Compute", "virtualMachines", id.VirtualMachineName) if err != nil { - return nil, fmt.Errorf("reading Server Vulnerability Assessment (%s/%s): %+v", resourceGroup, name, err) + return nil, fmt.Errorf("reading %s: %+v", id, err) } return utils.Bool(resp.ID != nil), nil diff --git a/website/docs/r/security_center_hybrid_vm_server_vulnerability_assessment.html.markdown b/website/docs/r/security_center_hybrid_vm_server_vulnerability_assessment.html.markdown deleted file mode 100644 index c9d2c56a30b4..000000000000 --- a/website/docs/r/security_center_hybrid_vm_server_vulnerability_assessment.html.markdown +++ /dev/null @@ -1,51 +0,0 @@ ---- -subcategory: "Security Center" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_security_center_hyrbid_vm_server_vulnerability_assessment" -description: |- - Manages an Azure Vulnerability Assessment (Qualys) to an Azure ARC server. ---- - -# azurerm_security_center_hyrbid_vm_server_vulnerability_assessment - -Manages an Azure Server Vulnerability Assessment (Qualys) to a VM. - --> **NOTE** Azure Defender has to be enabled on the subscription in order for this resource to work. -See this [documentation](https://docs.microsoft.com/en-us/azure/security-center/security-center-get-started) to get started. - -## Example Usage - -```hcl -resource "azurerm_security_center_hyrbid_vm_server_vulnerability_assessment" "example" { - hydrid_machine_id = "/hybrid/machine/id" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `hybrid_machine_id` - (Required) The ID of the Azure ARC server to be monitored by vulnerability assessment. Changing this forces a new resource to be created. - - -## Attributes Reference - -In addition to all arguments above, the following attributes are exported: - -* `id` - The ID of the Vulnerability Assessment resource. - -## Timeouts - -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: - -* `create` - (Defaults to 5 minutes) Used when creating the Advanced Threat Protection. -* `read` - (Defaults to 5 minutes) Used when retrieving the Advanced Threat Protection. -* `delete` - (Defaults to 10 minutes) Used when deleting the Advanced Threat Protection. - -## Import - -Server Vulnerability Assessments can be imported using the `resource id`, e.g. - -```shell -terraform import azurerm_security_center_hyrbid_vm_server_vulnerability_assessment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.HybridCompute/machines/machine-name/providers/Microsoft.Security/serverVulnerabilityAssessments/Default -``` diff --git a/website/docs/r/security_center_server_vulnerability_assessment_arc_virtual_machine.html.markdown b/website/docs/r/security_center_server_vulnerability_assessment_arc_virtual_machine.html.markdown new file mode 100644 index 000000000000..a601f556e1ee --- /dev/null +++ b/website/docs/r/security_center_server_vulnerability_assessment_arc_virtual_machine.html.markdown @@ -0,0 +1,56 @@ +--- +subcategory: "Security Center" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_security_center_server_vulnerability_assessment_arc_virtual_machine" +description: |- + Manages an Azure Vulnerability Assessment (Qualys) to an Azure ARC server. +--- + +# azurerm_security_center_server_vulnerability_assessment_arc_virtual_machine + +Manages an Azure Server Vulnerability Assessment (Qualys) to a VM. + +-> **NOTE** Azure Defender has to be enabled on the subscription in order for this resource to work. +See this [documentation](https://docs.microsoft.com/azure/security-center/security-center-get-started) to get started. + +## Example Usage + +```hcl +data "azurerm_virtual_machine" "example" { + name = "example-virtual-machine" + resource_group_name = "example-resources" +} + +resource "azurerm_security_center_server_vulnerability_assessment_arc_virtual_machine" "example" { + hydrid_machine_id = data.azurerm_virtual_machine.example.id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `hybrid_machine_id` - (Required) The ID of the Arc Virtual Machine which should have a Vulnerability Assessment configured. Changing this forces a new resource to be created. + + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID of the Arc Virtual Machine Server Vulnerability Assessment. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 5 minutes) Used when creating the Arc Virtual Machine Server Vulnerability Assessment. +* `read` - (Defaults to 5 minutes) Used when retrieving the Arc Virtual Machine Server Vulnerability Assessment. +* `delete` - (Defaults to 10 minutes) Used when deleting the Arc Virtual Machine Server Vulnerability Assessment. + +## Import + +Arc Virtual Machine Server Vulnerability Assessments can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_security_center_server_vulnerability_assessment_arc_virtual_machine.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.HybridCompute/machines/machine-name/providers/Microsoft.Security/serverVulnerabilityAssessments/Default +``` diff --git a/website/docs/r/security_center_vm_server_vulnerability_assessment.html.markdown b/website/docs/r/security_center_server_vulnerability_assessment_virtual_machine.html.markdown similarity index 81% rename from website/docs/r/security_center_vm_server_vulnerability_assessment.html.markdown rename to website/docs/r/security_center_server_vulnerability_assessment_virtual_machine.html.markdown index cdafa4079759..69a285091b59 100644 --- a/website/docs/r/security_center_vm_server_vulnerability_assessment.html.markdown +++ b/website/docs/r/security_center_server_vulnerability_assessment_virtual_machine.html.markdown @@ -1,21 +1,22 @@ --- subcategory: "Security Center" layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_security_center_vm_server_vulnerability_assessment" +page_title: "Azure Resource Manager: azurerm_security_center_server_vulnerability_assessment_virtual_machine" description: |- Manages an Azure Vulnerability Assessment (Qualys) to a VM. --- -# azurerm_security_center_vm_server_vulnerability_assessment +# azurerm_security_center_server_vulnerability_assessment_virtual_machine Manages an Azure Server Vulnerability Assessment (Qualys) to a VM. -> **NOTE** Azure Defender has to be enabled on the subscription in order for this resource to work. -See this [documentation](https://docs.microsoft.com/en-us/azure/security-center/security-center-get-started) to get started. +See this [documentation](https://docs.microsoft.com/azure/security-center/security-center-get-started) to get started. ## Example Usage ```hcl + resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" @@ -72,7 +73,7 @@ resource "azurerm_linux_virtual_machine" "example" { network_interface_ids = [azurerm_network_interface.example.id] } -resource "azurerm_security_center_vm_server_vulnerability_assessment" "example" { +resource "azurerm_security_center_server_vulnerability_assessment_virtual_machine" "example" { virtual_machine_id = azurerm_linux_virtual_machine.example.id } ``` @@ -102,6 +103,6 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/d Server Vulnerability Assessments can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_security_center_vm_server_vulnerability_assessment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachines/vm-name/providers/Microsoft.Security/serverVulnerabilityAssessments/Default +terraform import azurerm_security_center_server_vulnerability_assessment_virtual_machine.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resource-group-name/providers/Microsoft.Compute/virtualMachines/vm-name/providers/Microsoft.Security/serverVulnerabilityAssessments/Default ```