Skip to content

Commit

Permalink
correct ids and docs naming
Browse files Browse the repository at this point in the history
  • Loading branch information
catriona-m committed Mar 21, 2022
1 parent 9607f2b commit 58ef1ab
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"},
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
```
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
```
Expand Down Expand Up @@ -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
```

0 comments on commit 58ef1ab

Please sign in to comment.