From f14aaf514d565f80a5728ff50acc0ff909ab8acc Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 15 Sep 2023 13:28:52 -0700 Subject: [PATCH] dependencies - swap Virtual Machine Scale Set Ids for `hashicorp/go-azure-helpers/commonids` (#23272) --- internal/services/compute/client/client.go | 8 +- .../services/compute/image_resource_test.go | 6 +- .../compute/linux_virtual_machine_resource.go | 3 +- ...inux_virtual_machine_scale_set_resource.go | 62 ++--- ...l_machine_scale_set_resource_other_test.go | 8 +- ...virtual_machine_scale_set_resource_test.go | 8 +- ...d_virtual_machine_scale_set_data_source.go | 6 +- ...ated_virtual_machine_scale_set_resource.go | 74 +++--- ...machine_scale_set_resource_network_test.go | 6 +- ...virtual_machine_scale_set_resource_test.go | 14 +- .../parse/virtual_machine_scale_set.go | 116 --------- .../parse/virtual_machine_scale_set_test.go | 232 ------------------ internal/services/compute/resourceids.go | 1 - .../validate/virtual_machine_scale_set_id.go | 26 -- .../virtual_machine_scale_set_id_test.go | 79 ------ .../virtual_machine_scale_set_data_source.go | 14 +- ...al_machine_scale_set_extension_resource.go | 8 +- .../virtual_machine_scale_set_import.go | 22 +- .../virtual_machine_scale_set_update.go | 48 ++-- .../windows_virtual_machine_resource.go | 3 +- ...dows_virtual_machine_scale_set_resource.go | 62 ++--- ...l_machine_scale_set_resource_other_test.go | 8 +- ...virtual_machine_scale_set_resource_test.go | 8 +- .../virtual_machine_scale_set_resource.go | 27 +- ...virtual_machine_scale_set_resource_test.go | 20 +- ...ment_virtual_machine_scale_set_resource.go | 11 +- ...ment_virtual_machine_scale_set_v0_to_v1.go | 4 +- ...ce_assignment_virtual_machine_scale_set.go | 6 +- ...signment_virtual_machine_scale_set_test.go | 10 +- ...chine_scale_set_packet_capture_resource.go | 3 +- .../site_recovery_replicated_vm_resource.go | 6 +- 31 files changed, 226 insertions(+), 683 deletions(-) delete mode 100644 internal/services/compute/parse/virtual_machine_scale_set.go delete mode 100644 internal/services/compute/parse/virtual_machine_scale_set_test.go delete mode 100644 internal/services/compute/validate/virtual_machine_scale_set_id.go delete mode 100644 internal/services/compute/validate/virtual_machine_scale_set_id_test.go diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index 33030a1779ba..796ae11379d6 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -9,6 +9,7 @@ import ( "log" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-07-01/skus" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/availabilitysets" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedhostgroups" @@ -29,7 +30,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2023-04-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/marketplaceordering/2015-06-01/agreements" "github.com/hashicorp/terraform-provider-azurerm/internal/common" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/utils" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) @@ -251,8 +251,8 @@ func NewClient(o *common.ClientOptions) (*Client, error) { }, nil } -func (c *Client) CancelRollingUpgradesBeforeDeletion(ctx context.Context, id parse.VirtualMachineScaleSetId) error { - resp, err := c.VMScaleSetRollingUpgradesClient.GetLatest(ctx, id.ResourceGroup, id.Name) +func (c *Client) CancelRollingUpgradesBeforeDeletion(ctx context.Context, id commonids.VirtualMachineScaleSetId) error { + resp, err := c.VMScaleSetRollingUpgradesClient.GetLatest(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName) if err != nil { // No rolling upgrades are running so skipping attempt to cancel them before deletion if utils.ResponseWasNotFound(resp.Response) { @@ -271,7 +271,7 @@ func (c *Client) CancelRollingUpgradesBeforeDeletion(ctx context.Context, id par return nil } - future, err := c.VMScaleSetRollingUpgradesClient.Cancel(ctx, id.ResourceGroup, id.Name) + future, err := c.VMScaleSetRollingUpgradesClient.Cancel(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName) if err != nil { // If there is no rolling upgrade the API will throw a 409/No rolling upgrade to cancel // we don't error out in this case diff --git a/internal/services/compute/image_resource_test.go b/internal/services/compute/image_resource_test.go index 748e59c779df..7ae8f5a51115 100644 --- a/internal/services/compute/image_resource_test.go +++ b/internal/services/compute/image_resource_test.go @@ -12,13 +12,13 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/virtualmachines" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-01/images" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/ssh" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" networkParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -332,13 +332,13 @@ func (ImageResource) virtualMachineExists(ctx context.Context, client *clients.C } func (ImageResource) virtualMachineScaleSetExists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, "") + resp, err := client.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { return fmt.Errorf("%s does not exist", *id) diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index f33b4569c80a..a6f0a0a0cb16 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -11,6 +11,7 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/availabilitysets" @@ -337,7 +338,7 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { ConflictsWith: []string{ "availability_set_id", }, - ValidateFunc: computeValidate.VirtualMachineScaleSetID, + ValidateFunc: commonids.ValidateVirtualMachineScaleSetID, }, "vtpm_enabled": { diff --git a/internal/services/compute/linux_virtual_machine_scale_set_resource.go b/internal/services/compute/linux_virtual_machine_scale_set_resource.go index bd69b717bbd7..815d28fcaf00 100644 --- a/internal/services/compute/linux_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/linux_virtual_machine_scale_set_resource.go @@ -8,6 +8,7 @@ import ( "log" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" @@ -20,7 +21,6 @@ import ( azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/base64" @@ -40,7 +40,7 @@ func resourceLinuxVirtualMachineScaleSet() *pluginsdk.Resource { Delete: resourceLinuxVirtualMachineScaleSetDelete, Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { - _, err := parse.VirtualMachineScaleSetID(id) + _, err := commonids.ParseVirtualMachineScaleSetID(id) return err }, importVirtualMachineScaleSet(compute.OperatingSystemTypesLinux, "azurerm_linux_virtual_machine_scale_set")), @@ -64,10 +64,10 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := commonids.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method - exists, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + exists, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if !utils.ResponseWasNotFound(exists.Response) { return fmt.Errorf("checking for existing Linux %s: %+v", id, err) @@ -159,7 +159,7 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i if len(errs) > 0 { return fmt.Errorf("unable to assume default computer name prefix %s. Please adjust the %q, or specify an explicit %q", errs[0], "name", "computer_name_prefix") } - computerNamePrefix = id.Name + computerNamePrefix = id.VirtualMachineScaleSetName } disablePasswordAuthentication := d.Get("disable_password_authentication").(bool) @@ -445,7 +445,7 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i } log.Printf("[DEBUG] Creating Linux %s", id) - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, props) if err != nil { return fmt.Errorf("creating Linux %s: %+v", id, err) } @@ -466,7 +466,7 @@ func resourceLinuxVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -475,18 +475,18 @@ func resourceLinuxVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta i // retrieve // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Linux %s: %+v", id, err) } if existing.VirtualMachineScaleSetProperties == nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Linux %s: `properties` was nil", id) } if existing.VirtualMachineScaleSetProperties.VirtualMachineProfile == nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Linux %s: `properties.virtualMachineProfile` was nil", id) } if existing.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile == nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile,storageProfile` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Linux %s: `properties.virtualMachineProfile,storageProfile` was nil", id) } updateProps := compute.VirtualMachineScaleSetUpdateProperties{ @@ -808,25 +808,25 @@ func resourceLinuxVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta int ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Linux Virtual Machine Scale Set %q was not found in Resource Group %q - removing from state!", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Linux %s - removing from state!", id) d.SetId("") return nil } - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Linux %s: %+v", id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.VirtualMachineScaleSetName) + d.Set("resource_group_name", id.ResourceGroupName) d.Set("location", location.NormalizeNilable(resp.Location)) d.Set("edge_zone", flattenEdgeZone(resp.ExtendedLocation)) d.Set("zones", zones.FlattenUntyped(resp.Zones)) @@ -855,7 +855,7 @@ func resourceLinuxVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta int } if resp.VirtualMachineScaleSetProperties == nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Linux %s: `properties` was nil", id) } props := *resp.VirtualMachineScaleSetProperties @@ -1075,19 +1075,19 @@ func resourceLinuxVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(resp.Response) { return nil } - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Linux %s: %+v", id, err) } // If rolling upgrades are configured and running we need to cancel them before trying to delete the VMSS @@ -1109,36 +1109,36 @@ func resourceLinuxVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta i update := compute.VirtualMachineScaleSetUpdate{ Sku: resp.Sku, } - future, err := client.Update(ctx, id.ResourceGroup, id.Name, update) + future, err := client.Update(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, update) if err != nil { - return fmt.Errorf("updating number of instances in Linux Virtual Machine Scale Set %q (Resource Group %q) to scale to 0: %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating number of instances in %s to scale to 0: %+v", id, err) } log.Printf("[DEBUG] Waiting for scaling of instances to 0 prior to deletion - this helps avoids networking issues within Azure") err = future.WaitForCompletionRef(ctx, client.Client) if err != nil { - return fmt.Errorf("waiting for number of instances in Linux Virtual Machine Scale Set %q (Resource Group %q) to scale to 0: %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for number of instances in Linux %s to scale to 0: %+v", id, err) } log.Printf("[DEBUG] Scaled instances to 0 prior to deletion - this helps avoids networking issues within Azure") } else { log.Printf("[DEBUG] Unable to scale instances to `0` since the `sku` block is nil - trying to delete anyway") } - log.Printf("[DEBUG] Deleting Linux Virtual Machine Scale Set %q (Resource Group %q)..", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Deleting Linux %s", id) // @ArcturusZhang (mimicking from linux_virtual_machine_pluginsdk.go): sending `nil` here omits this value from being sent // which matches the previous behaviour - we're only splitting this out so it's clear why // TODO: support force deletion once it's out of Preview, if applicable var forceDeletion *bool = nil - future, err := client.Delete(ctx, id.ResourceGroup, id.Name, forceDeletion) + future, err := client.Delete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, forceDeletion) if err != nil { - return fmt.Errorf("deleting Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("deleting Linux %s: %+v", id, err) } - log.Printf("[DEBUG] Waiting for deletion of Linux Virtual Machine Scale Set %q (Resource Group %q)..", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Waiting for deletion of Linux %s", id) if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for deletion of Linux %s: %+v", id, err) } - log.Printf("[DEBUG] Deleted Linux Virtual Machine Scale Set %q (Resource Group %q).", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Deleted Linux %s", id) return nil } diff --git a/internal/services/compute/linux_virtual_machine_scale_set_resource_other_test.go b/internal/services/compute/linux_virtual_machine_scale_set_resource_other_test.go index 5cd7216f487a..867c46ace0c6 100644 --- a/internal/services/compute/linux_virtual_machine_scale_set_resource_other_test.go +++ b/internal/services/compute/linux_virtual_machine_scale_set_resource_other_test.go @@ -10,11 +10,11 @@ import ( "testing" "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-plugin-testing/terraform" "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/compute/parse" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) @@ -803,12 +803,12 @@ func TestAccLinuxVirtualMachineScaleSet_otherCancelRollingUpgrades(t *testing.T) // and simulates the scenario where rolling upgrades are running when we try to delete a VMSS client := clients.Compute.VMScaleSetClient - id, err := parse.VirtualMachineScaleSetID(state.Attributes["id"]) + id, err := commonids.ParseVirtualMachineScaleSetID(state.Attributes["id"]) if err != nil { return err } - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return fmt.Errorf("retrieving %s: %+v", *id, err) } @@ -834,7 +834,7 @@ func TestAccLinuxVirtualMachineScaleSet_otherCancelRollingUpgrades(t *testing.T) VirtualMachineScaleSetUpdateProperties: &updateProps, } - if _, err := client.Update(ctx, id.ResourceGroup, id.Name, update); err != nil { + if _, err := client.Update(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, update); err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } diff --git a/internal/services/compute/linux_virtual_machine_scale_set_resource_test.go b/internal/services/compute/linux_virtual_machine_scale_set_resource_test.go index f6140866a1d5..30f455ce738e 100644 --- a/internal/services/compute/linux_virtual_machine_scale_set_resource_test.go +++ b/internal/services/compute/linux_virtual_machine_scale_set_resource_test.go @@ -7,9 +7,9 @@ import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -17,14 +17,14 @@ import ( type LinuxVirtualMachineScaleSetResource struct{} func (r LinuxVirtualMachineScaleSetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return nil, err } - resp, err := clients.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, "") + resp, err := clients.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "") if err != nil { - return nil, fmt.Errorf("retrieving Compute Linux Virtual Machine Scale Set %q: %+v", id, err) + return nil, fmt.Errorf("retrieving Linux %s: %+v", id, err) } return utils.Bool(resp.ID != nil), nil diff --git a/internal/services/compute/orchestrated_virtual_machine_scale_set_data_source.go b/internal/services/compute/orchestrated_virtual_machine_scale_set_data_source.go index a34f57fd48b8..7f044b3e6aa3 100644 --- a/internal/services/compute/orchestrated_virtual_machine_scale_set_data_source.go +++ b/internal/services/compute/orchestrated_virtual_machine_scale_set_data_source.go @@ -8,11 +8,11 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" computeValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -149,9 +149,9 @@ func (r OrchestratedVirtualMachineScaleSetDataSource) Read() sdk.ResourceFunc { return err } - id := parse.NewVirtualMachineScaleSetID(subscriptionId, orchestratedVMSS.ResourceGroup, orchestratedVMSS.Name) + id := commonids.NewVirtualMachineScaleSetID(subscriptionId, orchestratedVMSS.ResourceGroup, orchestratedVMSS.Name) - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("%s not found", id) diff --git a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go index 9b9f647f770c..82320f6993f6 100644 --- a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" @@ -22,7 +23,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" computeValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -41,7 +41,7 @@ func resourceOrchestratedVirtualMachineScaleSet() *pluginsdk.Resource { Delete: resourceOrchestratedVirtualMachineScaleSetDelete, Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { - _, err := parse.VirtualMachineScaleSetID(id) + _, err := commonids.ParseVirtualMachineScaleSetID(id) return err }, importOrchestratedVirtualMachineScaleSet), @@ -277,11 +277,11 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, defer cancel() isLegacy := true - id := parse.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := commonids.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("checking for existing %s: %+v", id, err) @@ -375,7 +375,7 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, } if hasHealthExtension { - log.Printf("[DEBUG] Orchestrated Virtual Machine Scale Set %q (Resource Group %q) has a Health Extension defined", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Orchestrated %s has a Health Extension defined", id) } if v, ok := d.GetOk("extensions_time_budget"); ok { @@ -423,11 +423,11 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, // if the Computer Prefix Name was not defined use the computer name if vmssOsProfile.ComputerNamePrefix == nil || len(*vmssOsProfile.ComputerNamePrefix) == 0 { // validate that the computer name is a valid Computer Prefix Name - _, errs := computeValidate.WindowsComputerNamePrefix(id.Name, "computer_name_prefix") + _, errs := computeValidate.WindowsComputerNamePrefix(id.VirtualMachineScaleSetName, "computer_name_prefix") if len(errs) > 0 { return fmt.Errorf("unable to assume default computer name prefix %s. Please adjust the 'name', or specify an explicit 'computer_name_prefix'", errs[0]) } - vmssOsProfile.ComputerNamePrefix = utils.String(id.Name) + vmssOsProfile.ComputerNamePrefix = utils.String(id.VirtualMachineScaleSetName) } if extensionOperationsEnabled && !provisionVMAgent { @@ -488,12 +488,12 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, // if the Computer Prefix Name was not defined use the computer name if vmssOsProfile.ComputerNamePrefix == nil || len(*vmssOsProfile.ComputerNamePrefix) == 0 { // validate that the computer name is a valid Computer Prefix Name - _, errs := computeValidate.LinuxComputerNamePrefix(id.Name, "computer_name_prefix") + _, errs := computeValidate.LinuxComputerNamePrefix(id.VirtualMachineScaleSetName, "computer_name_prefix") if len(errs) > 0 { return fmt.Errorf("unable to assume default computer name prefix %s. Please adjust the 'name', or specify an explicit 'computer_name_prefix'", errs[0]) } - vmssOsProfile.ComputerNamePrefix = utils.String(id.Name) + vmssOsProfile.ComputerNamePrefix = utils.String(id.VirtualMachineScaleSetName) } if extensionOperationsEnabled && !provisionVMAgent { @@ -640,7 +640,7 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, } log.Printf("[DEBUG] Creating Orchestrated %s.", id) - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, props) if err != nil { return fmt.Errorf("creating Orchestrated %s: %+v", id, err) } @@ -654,7 +654,7 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, for { log.Printf("[DEBUG] Retrying PUT %d for Orchestrated %s.", errCount, id) - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, props) if err != nil { return fmt.Errorf("creating Orchestrated %s after %d retries: %+v", id, errCount, err) } @@ -694,7 +694,7 @@ func resourceOrchestratedVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -706,23 +706,23 @@ func resourceOrchestratedVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, // retrieve // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Orchestrated %s: %+v", id, err) } if existing.Sku != nil { isLegacy = false } if existing.VirtualMachineScaleSetProperties == nil { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Orchestrated %s: `properties` was nil", id) } if !isLegacy { if existing.VirtualMachineScaleSetProperties.VirtualMachineProfile == nil { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Orchestrated %s: `properties.virtualMachineProfile` was nil", id) } if existing.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile == nil { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile,storageProfile` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Orchestrated %s: `properties.virtualMachineProfile,storageProfile` was nil", id) } } @@ -1099,7 +1099,7 @@ func resourceOrchestratedVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, update.VirtualMachineScaleSetUpdateProperties = &updateProps if updateInstances { - log.Printf("[DEBUG] Orchestrated Virtual Machine Scale Set %q in Resource Group %q - updateInstances is true", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Orchestrated %s - updateInstances is true", id) } // AutomaticOSUpgradeIsEnabled currently is not supported in orchestrated VMSS flex @@ -1127,25 +1127,25 @@ func resourceOrchestratedVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, m ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Orchestrated Virtual Machine Scale Set %q was not found in Resource Group %q - removing from state!", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Orchestrated %s was not found - removing from state!", id) d.SetId("") return nil } - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Orchestrated %s: %+v", id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.VirtualMachineScaleSetName) + d.Set("resource_group_name", id.ResourceGroupName) d.Set("location", location.NormalizeNilable(resp.Location)) d.Set("zones", zones.FlattenUntyped(resp.Zones)) @@ -1178,7 +1178,7 @@ func resourceOrchestratedVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, m } if resp.VirtualMachineScaleSetProperties == nil { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Orchestrated %s: `properties` was nil", id) } props := *resp.VirtualMachineScaleSetProperties @@ -1319,19 +1319,19 @@ func resourceOrchestratedVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(resp.Response) { return nil } - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Orchestrated %s: %+v", id, err) } // Sometimes VMSS's aren't fully deleted when the `Delete` call returns - as such we'll try to scale the cluster @@ -1347,36 +1347,36 @@ func resourceOrchestratedVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, update := compute.VirtualMachineScaleSetUpdate{ Sku: resp.Sku, } - future, err := client.Update(ctx, id.ResourceGroup, id.Name, update) + future, err := client.Update(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, update) if err != nil { - return fmt.Errorf("updating number of instances in Orchestrated Virtual Machine Scale Set %q (Resource Group %q) to scale to 0: %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating number of instances in Orchestrated %s to scale to 0: %+v", id, err) } log.Printf("[DEBUG] Waiting for scaling of instances to 0 prior to deletion - this helps avoids networking issues within Azure") err = future.WaitForCompletionRef(ctx, client.Client) if err != nil { - return fmt.Errorf("waiting for number of instances in Orchestrated Virtual Machine Scale Set %q (Resource Group %q) to scale to 0: %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for number of instances in Orchestrated %s to scale to 0: %+v", id, err) } log.Printf("[DEBUG] Scaled instances to 0 prior to deletion - this helps avoids networking issues within Azure") } else { log.Printf("[DEBUG] Unable to scale instances to `0` since the `sku` block is nil - trying to delete anyway") } - log.Printf("[DEBUG] Deleting Orchestrated Virtual Machine Scale Set %q (Resource Group %q)..", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Deleting Orchestrated %s", id) // @ArcturusZhang (mimicking from windows_virtual_machine_pluginsdk.go): sending `nil` here omits this value from being sent // which matches the previous behaviour - we're only splitting this out so it's clear why // TODO: support force deletion once it's out of Preview, if applicable var forceDeletion *bool = nil - future, err := client.Delete(ctx, id.ResourceGroup, id.Name, forceDeletion) + future, err := client.Delete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, forceDeletion) if err != nil { - return fmt.Errorf("deleting Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("deleting Orchestrated %s: %+v", id, err) } - log.Printf("[DEBUG] Waiting for deletion of Orchestrated Virtual Machine Scale Set %q (Resource Group %q)..", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Waiting for deletion of Orchestrated %s", id) if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for deletion of Orchestrated %s: %+v", id, err) } - log.Printf("[DEBUG] Deleted Orchestrated Virtual Machine Scale Set %q (Resource Group %q).", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Deleted Orchestrated %s", id) return nil } diff --git a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_network_test.go b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_network_test.go index 28ef0f46cb6b..faca57cb4bed 100644 --- a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_network_test.go +++ b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_network_test.go @@ -8,10 +8,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "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/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) @@ -246,13 +246,13 @@ func TestAccOrchestratedVirtualMachineScaleSet_networkPublicIPVersion(t *testing } func (OrchestratedVirtualMachineScaleSetResource) hasLoadBalancer(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - read, err := client.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + read, err := client.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return err } diff --git a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_test.go b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_test.go index 62b36fa217c1..c8adcb0973a9 100644 --- a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_test.go +++ b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource_test.go @@ -8,10 +8,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "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/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" @@ -487,13 +487,13 @@ func TestAccOrchestratedVirtualMachineScaleSet_updatePriorityMixPolicy(t *testin // } func (t OrchestratedVirtualMachineScaleSetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return nil, err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := clients.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := clients.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return nil, fmt.Errorf("retrieving Virtual Machine Scale Set %q", id) } @@ -502,14 +502,14 @@ func (t OrchestratedVirtualMachineScaleSetResource) Exists(ctx context.Context, } func (OrchestratedVirtualMachineScaleSetResource) Destroy(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return nil, err } // this is a preview feature we don't want to use right now var forceDelete *bool = nil - future, err := client.Compute.VMScaleSetClient.Delete(ctx, id.ResourceGroup, id.Name, forceDelete) + future, err := client.Compute.VMScaleSetClient.Delete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, forceDelete) if err != nil { return nil, fmt.Errorf("Bad: deleting %s: %+v", *id, err) } @@ -522,13 +522,13 @@ func (OrchestratedVirtualMachineScaleSetResource) Destroy(ctx context.Context, c } func (OrchestratedVirtualMachineScaleSetResource) hasApplicationGateway(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - read, err := client.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + read, err := client.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return err } diff --git a/internal/services/compute/parse/virtual_machine_scale_set.go b/internal/services/compute/parse/virtual_machine_scale_set.go deleted file mode 100644 index 1fdff2bfe27e..000000000000 --- a/internal/services/compute/parse/virtual_machine_scale_set.go +++ /dev/null @@ -1,116 +0,0 @@ -// 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 VirtualMachineScaleSetId struct { - SubscriptionId string - ResourceGroup string - Name string -} - -func NewVirtualMachineScaleSetID(subscriptionId, resourceGroup, name string) VirtualMachineScaleSetId { - return VirtualMachineScaleSetId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - Name: name, - } -} - -func (id VirtualMachineScaleSetId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Virtual Machine Scale Set", segmentsStr) -} - -func (id VirtualMachineScaleSetId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name) -} - -// VirtualMachineScaleSetID parses a VirtualMachineScaleSet ID into an VirtualMachineScaleSetId struct -func VirtualMachineScaleSetID(input string) (*VirtualMachineScaleSetId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, fmt.Errorf("parsing %q as an VirtualMachineScaleSet ID: %+v", input, err) - } - - resourceId := VirtualMachineScaleSetId{ - 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.Name, err = id.PopSegment("virtualMachineScaleSets"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} - -// VirtualMachineScaleSetIDInsensitively parses an VirtualMachineScaleSet ID into an VirtualMachineScaleSetId struct, insensitively -// This should only be used to parse an ID for rewriting, the VirtualMachineScaleSetID -// method should be used instead for validation etc. -// -// Whilst this may seem strange, this enables Terraform have consistent casing -// which works around issues in Core, whilst handling broken API responses. -func VirtualMachineScaleSetIDInsensitively(input string) (*VirtualMachineScaleSetId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := VirtualMachineScaleSetId{ - 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") - } - - // find the correct casing for the 'virtualMachineScaleSets' segment - virtualMachineScaleSetsKey := "virtualMachineScaleSets" - for key := range id.Path { - if strings.EqualFold(key, virtualMachineScaleSetsKey) { - virtualMachineScaleSetsKey = key - break - } - } - if resourceId.Name, err = id.PopSegment(virtualMachineScaleSetsKey); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} diff --git a/internal/services/compute/parse/virtual_machine_scale_set_test.go b/internal/services/compute/parse/virtual_machine_scale_set_test.go deleted file mode 100644 index 0e428925adcf..000000000000 --- a/internal/services/compute/parse/virtual_machine_scale_set_test.go +++ /dev/null @@ -1,232 +0,0 @@ -// 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 = VirtualMachineScaleSetId{} - -func TestVirtualMachineScaleSetIDFormatter(t *testing.T) { - actual := NewVirtualMachineScaleSetID("12345678-1234-9876-4563-123456789012", "resGroup1", "scaleSet1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleSet1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestVirtualMachineScaleSetID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *VirtualMachineScaleSetId - }{ - - { - // 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 Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/", - Error: true, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleSet1", - Expected: &VirtualMachineScaleSetId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "scaleSet1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.COMPUTE/VIRTUALMACHINESCALESETS/SCALESET1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := VirtualMachineScaleSetID(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} - -func TestVirtualMachineScaleSetIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *VirtualMachineScaleSetId - }{ - - { - // 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 Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/", - Error: true, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleSet1", - Expected: &VirtualMachineScaleSetId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "scaleSet1", - }, - }, - - { - // lower-cased segment names - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualmachinescalesets/scaleSet1", - Expected: &VirtualMachineScaleSetId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "scaleSet1", - }, - }, - - { - // upper-cased segment names - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/VIRTUALMACHINESCALESETS/scaleSet1", - Expected: &VirtualMachineScaleSetId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "scaleSet1", - }, - }, - - { - // mixed-cased segment names - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/ViRtUaLmAcHiNeScAlEsEtS/scaleSet1", - Expected: &VirtualMachineScaleSetId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - Name: "scaleSet1", - }, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := VirtualMachineScaleSetIDInsensitively(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.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - } -} diff --git a/internal/services/compute/resourceids.go b/internal/services/compute/resourceids.go index 1430284d7703..b45c839dc04d 100644 --- a/internal/services/compute/resourceids.go +++ b/internal/services/compute/resourceids.go @@ -8,7 +8,6 @@ package compute //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SharedImageVersion -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/galleries/gallery1/images/image1/versions/version1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualMachine -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualMachineExtension -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachines/machine1/extensions/extension1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualMachineScaleSet -rewrite=true -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleSet1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=VirtualMachineScaleSetExtension -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleSet1/extensions/extension1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SSHPublicKey -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/sshPublicKeys/sshpublickey1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=HybridMachine -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.HybridCompute/machines/machine1 diff --git a/internal/services/compute/validate/virtual_machine_scale_set_id.go b/internal/services/compute/validate/virtual_machine_scale_set_id.go deleted file mode 100644 index c876738e292d..000000000000 --- a/internal/services/compute/validate/virtual_machine_scale_set_id.go +++ /dev/null @@ -1,26 +0,0 @@ -// 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/compute/parse" -) - -func VirtualMachineScaleSetID(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.VirtualMachineScaleSetID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/compute/validate/virtual_machine_scale_set_id_test.go b/internal/services/compute/validate/virtual_machine_scale_set_id_test.go deleted file mode 100644 index a88a172705e1..000000000000 --- a/internal/services/compute/validate/virtual_machine_scale_set_id_test.go +++ /dev/null @@ -1,79 +0,0 @@ -// 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 TestVirtualMachineScaleSetID(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 ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Valid: false, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Valid: false, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/", - Valid: false, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/virtualMachineScaleSets/scaleSet1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.COMPUTE/VIRTUALMACHINESCALESETS/SCALESET1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := VirtualMachineScaleSetID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/compute/virtual_machine_scale_set_data_source.go b/internal/services/compute/virtual_machine_scale_set_data_source.go index 54ac01cd4269..b353aad041f2 100644 --- a/internal/services/compute/virtual_machine_scale_set_data_source.go +++ b/internal/services/compute/virtual_machine_scale_set_data_source.go @@ -10,10 +10,10 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" networkParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -128,10 +128,10 @@ func dataSourceVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta interf ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := commonids.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "") + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { return fmt.Errorf("%s was not found", id) @@ -165,7 +165,7 @@ func dataSourceVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta interf } instances := make([]interface{}, 0) - result, err := instancesClient.ListComplete(ctx, id.ResourceGroup, id.Name, "", "", "") + result, err := instancesClient.ListComplete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "", "", "") if err != nil { return fmt.Errorf("listing VM Instances for %q: %+v", id, err) } @@ -174,14 +174,14 @@ func dataSourceVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta interf for result.NotDone() { instance := result.Value() if instance.InstanceID != nil { - nics, err := networkInterfacesClient.ListVirtualMachineScaleSetVMNetworkInterfacesComplete(ctx, id.ResourceGroup, id.Name, *instance.InstanceID) + nics, err := networkInterfacesClient.ListVirtualMachineScaleSetVMNetworkInterfacesComplete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, *instance.InstanceID) if err != nil { if !utils.ResponseWasNotFound(nics.Response().Response) { return fmt.Errorf("listing Network Interfaces for VM Instance %q for %q: %+v", *instance.InstanceID, id, err) } // Network Interfaces of VM in Flexible VMSS are accessed from single VM - vm, err := vmClient.Get(ctx, id.ResourceGroup, *instance.InstanceID, "") + vm, err := vmClient.Get(ctx, id.ResourceGroupName, *instance.InstanceID, "") if err != nil { return fmt.Errorf("retrieving VM Instance %q for %q: %+v", *instance.InstanceID, id, err) } @@ -196,7 +196,7 @@ func dataSourceVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta interf } } - connInfo, err = getVirtualMachineScaleSetVMConnectionInfo(ctx, networkInterfaces, id.ResourceGroup, id.Name, *instance.InstanceID, publicIPAddressesClient) + connInfo, err = getVirtualMachineScaleSetVMConnectionInfo(ctx, networkInterfaces, id.ResourceGroupName, id.VirtualMachineScaleSetName, *instance.InstanceID, publicIPAddressesClient) if err != nil { return err } diff --git a/internal/services/compute/virtual_machine_scale_set_extension_resource.go b/internal/services/compute/virtual_machine_scale_set_extension_resource.go index 1f3cd08138cc..4250c56bdc08 100644 --- a/internal/services/compute/virtual_machine_scale_set_extension_resource.go +++ b/internal/services/compute/virtual_machine_scale_set_extension_resource.go @@ -8,10 +8,10 @@ import ( "log" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "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" @@ -55,7 +55,7 @@ func resourceVirtualMachineScaleSetExtension() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.VirtualMachineScaleSetID, + ValidateFunc: commonids.ValidateVirtualMachineScaleSetID, }, "publisher": { @@ -133,11 +133,11 @@ func resourceVirtualMachineScaleSetExtensionCreate(d *pluginsdk.ResourceData, me ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - virtualMachineScaleSetId, err := parse.VirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) + virtualMachineScaleSetId, err := commonids.ParseVirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) if err != nil { return err } - id := parse.NewVirtualMachineScaleSetExtensionID(virtualMachineScaleSetId.SubscriptionId, virtualMachineScaleSetId.ResourceGroup, virtualMachineScaleSetId.Name, d.Get("name").(string)) + id := parse.NewVirtualMachineScaleSetExtensionID(virtualMachineScaleSetId.SubscriptionId, virtualMachineScaleSetId.ResourceGroupName, virtualMachineScaleSetId.VirtualMachineScaleSetName, d.Get("name").(string)) resp, err := client.Get(ctx, id.ResourceGroup, id.VirtualMachineScaleSetName, id.ExtensionName, "") if err != nil { diff --git a/internal/services/compute/virtual_machine_scale_set_import.go b/internal/services/compute/virtual_machine_scale_set_import.go index e4ec383975c2..0029e0f4e56f 100644 --- a/internal/services/compute/virtual_machine_scale_set_import.go +++ b/internal/services/compute/virtual_machine_scale_set_import.go @@ -7,23 +7,23 @@ import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) func importOrchestratedVirtualMachineScaleSet(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) (data []*pluginsdk.ResourceData, err error) { - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return []*pluginsdk.ResourceData{}, err } client := meta.(*clients.Client).Compute.VMScaleSetClient // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - _, err = client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + _, err = client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { - return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving %s: %+v", id, err) } return []*pluginsdk.ResourceData{d}, nil @@ -31,28 +31,28 @@ func importOrchestratedVirtualMachineScaleSet(ctx context.Context, d *pluginsdk. func importVirtualMachineScaleSet(osType compute.OperatingSystemTypes, resourceType string) pluginsdk.ImporterFunc { return func(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) (data []*pluginsdk.ResourceData, err error) { - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return []*pluginsdk.ResourceData{}, err } client := meta.(*clients.Client).Compute.VMScaleSetClient // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - vm, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + vm, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { - return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving %s: %+v", id, err) } if vm.VirtualMachineScaleSetProperties == nil { - return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving %s: `properties` was nil", id) } if vm.VirtualMachineScaleSetProperties.VirtualMachineProfile == nil { - return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile` was nil", id.Name, id.ResourceGroup) + return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving %s: `properties.virtualMachineProfile` was nil", id) } if vm.VirtualMachineScaleSetProperties.VirtualMachineProfile.OsProfile == nil { - return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile.osProfile` was nil", id.Name, id.ResourceGroup) + return []*pluginsdk.ResourceData{}, fmt.Errorf("retrieving %s: `properties.virtualMachineProfile.osProfile` was nil", id) } isCorrectOS := false @@ -87,7 +87,7 @@ func importVirtualMachineScaleSet(osType compute.OperatingSystemTypes, resourceT } updatedExtensions, err = flattenVirtualMachineScaleSetExtensions(extensionsProfile, d) if err != nil { - return []*pluginsdk.ResourceData{}, fmt.Errorf("could not read VMSS extensions data for %q (resource group %q)", id.Name, id.ResourceGroup) + return []*pluginsdk.ResourceData{}, fmt.Errorf("could not read VMSS extensions data for %s", id) } } } diff --git a/internal/services/compute/virtual_machine_scale_set_update.go b/internal/services/compute/virtual_machine_scale_set_update.go index 2fce06523a19..46ad95e94d68 100644 --- a/internal/services/compute/virtual_machine_scale_set_update.go +++ b/internal/services/compute/virtual_machine_scale_set_update.go @@ -9,8 +9,8 @@ import ( "log" "strings" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/client" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/utils" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) @@ -27,7 +27,7 @@ type virtualMachineScaleSetUpdateMetaData struct { Client *client.Client Existing compute.VirtualMachineScaleSet - ID *parse.VirtualMachineScaleSetId + ID *commonids.VirtualMachineScaleSetId OSType compute.OperatingSystemTypes } @@ -89,17 +89,17 @@ func (metadata virtualMachineScaleSetUpdateMetaData) updateVmss(ctx context.Cont client := metadata.Client.VMScaleSetClient id := metadata.ID - log.Printf("[DEBUG] Updating %s Virtual Machine Scale Set %q (Resource Group %q)..", metadata.OSType, id.Name, id.ResourceGroup) - future, err := client.Update(ctx, id.ResourceGroup, id.Name, update) + log.Printf("[DEBUG] Updating %s %s", metadata.OSType, id) + future, err := client.Update(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, update) if err != nil { - return fmt.Errorf("updating %s Virtual Machine Scale Set %q (Resource Group %q): %+v", metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating %s %s: %+v", metadata.OSType, id, err) } - log.Printf("[DEBUG] Waiting for update of %s Virtual Machine Scale Set %q (Resource Group %q)..", metadata.OSType, id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Waiting for update of %s %s", metadata.OSType, id) if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for update of %s Virtual Machine Scale Set %q (Resource Group %q): %+v", metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for update of %s %s: %+v", metadata.OSType, id, err) } - log.Printf("[DEBUG] Updated %s Virtual Machine Scale Set %q (Resource Group %q).", metadata.OSType, id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Updated %s %s", metadata.OSType, id) return nil } @@ -109,17 +109,17 @@ func (metadata virtualMachineScaleSetUpdateMetaData) upgradeInstancesForAutomati rollingUpgradesClient := metadata.Client.VMScaleSetRollingUpgradesClient id := metadata.ID - log.Printf("[DEBUG] Updating instances for %s Virtual Machine Scale Set %q (Resource Group %q)..", metadata.OSType, id.Name, id.ResourceGroup) - future, err := rollingUpgradesClient.StartOSUpgrade(ctx, id.ResourceGroup, id.Name) + log.Printf("[DEBUG] Updating instances for %s %s", metadata.OSType, id) + future, err := rollingUpgradesClient.StartOSUpgrade(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName) if err != nil { - return fmt.Errorf("updating instances for %s Virtual Machine Scale Set %q (Resource Group %q): %+v", metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating instances for %s %s: %+v", metadata.OSType, id, err) } - log.Printf("[DEBUG] Waiting for update of instances for %s Virtual Machine Scale Set %q (Resource Group %q)..", metadata.OSType, id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Waiting for update of instances for %s %s", metadata.OSType, id) if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for update of instances for %s Virtual Machine Scale Set %q (Resource Group %q): %+v", metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for update of instances for %s %s: %+v", metadata.OSType, id, err) } - log.Printf("[DEBUG] Updated instances for %s Virtual Machine Scale Set %q (Resource Group %q).", metadata.OSType, id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Updated instances for %s %s.", metadata.OSType, id) return nil } @@ -128,11 +128,11 @@ func (metadata virtualMachineScaleSetUpdateMetaData) upgradeInstancesForManualUp client := metadata.Client.VMScaleSetClient id := metadata.ID - log.Printf("[DEBUG] Rolling the VM Instances for %s Virtual Machine Scale Set %q (Resource Group %q)..", metadata.OSType, id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Rolling the VM Instances for %s %s", metadata.OSType, id) instancesClient := metadata.Client.VMScaleSetVMsClient - instances, err := instancesClient.ListComplete(ctx, id.ResourceGroup, id.Name, "", "", "") + instances, err := instancesClient.ListComplete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "", "", "") if err != nil { - return fmt.Errorf("listing VM Instances for %s Virtual Machine Scale Set %q (Resource Group %q): %+v", metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("listing VM Instances for %s %s: %+v", metadata.OSType, id, err) } log.Printf("[DEBUG] Determining instances to roll..") @@ -160,13 +160,13 @@ func (metadata virtualMachineScaleSetUpdateMetaData) upgradeInstancesForManualUp ids := compute.VirtualMachineScaleSetVMInstanceRequiredIDs{ InstanceIds: &instanceIds, } - future, err := client.UpdateInstances(ctx, id.ResourceGroup, id.Name, ids) + future, err := client.UpdateInstances(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, ids) if err != nil { - return fmt.Errorf("updating Instance %q (%s VM Scale Set %q / Resource Group %q) to the Latest Configuration: %+v", instanceId, metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating Instance %q (%s %s) to the Latest Configuration: %+v", instanceId, metadata.OSType, id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for update of Instance %q (%s VM Scale Set %q / Resource Group %q) to the Latest Configuration: %+v", instanceId, metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for update of Instance %q (%s %s) to the Latest Configuration: %+v", instanceId, metadata.OSType, id, err) } log.Printf("[DEBUG] Updated Instance %q to the Latest Configuration.", instanceId) @@ -175,18 +175,18 @@ func (metadata virtualMachineScaleSetUpdateMetaData) upgradeInstancesForManualUp reimageInput := &compute.VirtualMachineScaleSetReimageParameters{ InstanceIds: &instanceIds, } - reimageFuture, err := client.Reimage(ctx, id.ResourceGroup, id.Name, reimageInput) + reimageFuture, err := client.Reimage(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, reimageInput) if err != nil { - return fmt.Errorf("reimaging Instance %q (%s VM Scale Set %q / Resource Group %q): %+v", instanceId, metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("reimaging Instance %q (%s %s): %+v", instanceId, metadata.OSType, id, err) } if err = reimageFuture.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for reimage of Instance %q (%s VM Scale Set %q / Resource Group %q): %+v", instanceId, metadata.OSType, id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for reimage of Instance %q (%s %s): %+v", instanceId, metadata.OSType, id, err) } log.Printf("[DEBUG] Reimaged Instance %q..", instanceId) } - log.Printf("[DEBUG] Rolled the VM Instances for %s Virtual Machine Scale Set %q (Resource Group %q).", metadata.OSType, id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Rolled the VM Instances for %s %s.", metadata.OSType, id) return nil } diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index 6d379077a861..7a4b3decde14 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/availabilitysets" @@ -366,7 +367,7 @@ func resourceWindowsVirtualMachine() *pluginsdk.Resource { ConflictsWith: []string{ "availability_set_id", }, - ValidateFunc: computeValidate.VirtualMachineScaleSetID, + ValidateFunc: commonids.ValidateVirtualMachineScaleSetID, }, "platform_fault_domain": { diff --git a/internal/services/compute/windows_virtual_machine_scale_set_resource.go b/internal/services/compute/windows_virtual_machine_scale_set_resource.go index 9ed998dcdad3..bc8e32412aff 100644 --- a/internal/services/compute/windows_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/windows_virtual_machine_scale_set_resource.go @@ -8,6 +8,7 @@ import ( "log" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" @@ -20,7 +21,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" computeValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/base64" @@ -40,7 +40,7 @@ func resourceWindowsVirtualMachineScaleSet() *pluginsdk.Resource { Delete: resourceWindowsVirtualMachineScaleSetDelete, Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { - _, err := parse.VirtualMachineScaleSetID(id) + _, err := commonids.ParseVirtualMachineScaleSetID(id) return err }, importVirtualMachineScaleSet(compute.OperatingSystemTypesWindows, "azurerm_windows_virtual_machine_scale_set")), @@ -64,8 +64,8 @@ func resourceWindowsVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - exists, err := client.Get(ctx, id.ResourceGroup, id.Name, "") + id := commonids.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + exists, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "") if err != nil { if !utils.ResponseWasNotFound(exists.Response) { return fmt.Errorf("checking for existing Windows %s: %+v", id, err) @@ -160,7 +160,7 @@ func resourceWindowsVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta if len(errs) > 0 { return fmt.Errorf("unable to assume default computer name prefix %s. Please adjust the %q, or specify an explicit %q", errs[0], "name", "computer_name_prefix") } - computerNamePrefix = id.Name + computerNamePrefix = id.VirtualMachineScaleSetName } networkProfile := &compute.VirtualMachineScaleSetNetworkProfile{ @@ -451,7 +451,7 @@ func resourceWindowsVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta } log.Printf("[DEBUG] Creating Windows %s.", id) - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, props) if err != nil { return fmt.Errorf("creating Windows %s: %+v", id, err) } @@ -472,7 +472,7 @@ func resourceWindowsVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -481,18 +481,18 @@ func resourceWindowsVirtualMachineScaleSetUpdate(d *pluginsdk.ResourceData, meta // retrieve // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Windows %s: %+v", id, err) } if existing.VirtualMachineScaleSetProperties == nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Windows %s: `properties` was nil", id) } if existing.VirtualMachineScaleSetProperties.VirtualMachineProfile == nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Windows %s: `properties.virtualMachineProfile` was nil", id) } if existing.VirtualMachineScaleSetProperties.VirtualMachineProfile.StorageProfile == nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): `properties.virtualMachineProfile,storageProfile` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Windows %s: `properties.virtualMachineProfile,storageProfile` was nil", id) } updateProps := compute.VirtualMachineScaleSetUpdateProperties{ @@ -827,24 +827,24 @@ func resourceWindowsVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Windows Virtual Machine Scale Set %q was not found in Resource Group %q - removing from state!", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Windows %s was not found - removing from state!", id) d.SetId("") return nil } - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Windows %s: %+v", id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.VirtualMachineScaleSetName) + d.Set("resource_group_name", id.ResourceGroupName) d.Set("location", location.NormalizeNilable(resp.Location)) d.Set("edge_zone", flattenEdgeZone(resp.ExtendedLocation)) d.Set("zones", zones.FlattenUntyped(resp.Zones)) @@ -873,7 +873,7 @@ func resourceWindowsVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta i } if resp.VirtualMachineScaleSetProperties == nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): `properties` was nil", id.Name, id.ResourceGroup) + return fmt.Errorf("retrieving Windows %s: `properties` was nil", id) } props := *resp.VirtualMachineScaleSetProperties @@ -1108,18 +1108,18 @@ func resourceWindowsVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "") + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { return nil } - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("retrieving Windows %s: %+v", id, err) } // If rolling upgrades are configured and running we need to cancel them before trying to delete the VMSS @@ -1141,36 +1141,36 @@ func resourceWindowsVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta update := compute.VirtualMachineScaleSetUpdate{ Sku: resp.Sku, } - future, err := client.Update(ctx, id.ResourceGroup, id.Name, update) + future, err := client.Update(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, update) if err != nil { - return fmt.Errorf("updating number of instances in Windows Virtual Machine Scale Set %q (Resource Group %q) to scale to 0: %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating number of instances in Windows %s to scale to 0: %+v", id, err) } log.Printf("[DEBUG] Waiting for scaling of instances to 0 prior to deletion - this helps avoids networking issues within Azure") err = future.WaitForCompletionRef(ctx, client.Client) if err != nil { - return fmt.Errorf("waiting for number of instances in Windows Virtual Machine Scale Set %q (Resource Group %q) to scale to 0: %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for number of instances in Windows %s to scale to 0: %+v", id, err) } log.Printf("[DEBUG] Scaled instances to 0 prior to deletion - this helps avoids networking issues within Azure") } else { log.Printf("[DEBUG] Unable to scale instances to `0` since the `sku` block is nil - trying to delete anyway") } - log.Printf("[DEBUG] Deleting Windows Virtual Machine Scale Set %q (Resource Group %q)..", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Deleting Windows %s", id) // @ArcturusZhang (mimicking from windows_virtual_machine_pluginsdk.go): sending `nil` here omits this value from being sent // which matches the previous behaviour - we're only splitting this out so it's clear why // TODO: support force deletion once it's out of Preview, if applicable var forceDeletion *bool = nil - future, err := client.Delete(ctx, id.ResourceGroup, id.Name, forceDeletion) + future, err := client.Delete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, forceDeletion) if err != nil { - return fmt.Errorf("deleting Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("deleting Windows %s: %+v", id, err) } - log.Printf("[DEBUG] Waiting for deletion of Windows Virtual Machine Scale Set %q (Resource Group %q)..", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Waiting for deletion of Windows %s.", id) if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("waiting for deletion of Windows %s: %+v", id, err) } - log.Printf("[DEBUG] Deleted Windows Virtual Machine Scale Set %q (Resource Group %q).", id.Name, id.ResourceGroup) + log.Printf("[DEBUG] Deleted Windows %s", id) return nil } diff --git a/internal/services/compute/windows_virtual_machine_scale_set_resource_other_test.go b/internal/services/compute/windows_virtual_machine_scale_set_resource_other_test.go index fc1957d606be..67aa46def682 100644 --- a/internal/services/compute/windows_virtual_machine_scale_set_resource_other_test.go +++ b/internal/services/compute/windows_virtual_machine_scale_set_resource_other_test.go @@ -10,11 +10,11 @@ import ( "testing" "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-plugin-testing/terraform" "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/compute/parse" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" ) @@ -943,12 +943,12 @@ func TestAccWindowsVirtualMachineScaleSet_otherCancelRollingUpgrades(t *testing. // and simulates the scenario where rolling upgrades are running when we try to delete a VMSS client := clients.Compute.VMScaleSetClient - id, err := parse.VirtualMachineScaleSetID(state.Attributes["id"]) + id, err := commonids.ParseVirtualMachineScaleSetID(state.Attributes["id"]) if err != nil { return err } - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return fmt.Errorf("retrieving %s: %+v", *id, err) } @@ -974,7 +974,7 @@ func TestAccWindowsVirtualMachineScaleSet_otherCancelRollingUpgrades(t *testing. VirtualMachineScaleSetUpdateProperties: &updateProps, } - if _, err := client.Update(ctx, id.ResourceGroup, id.Name, update); err != nil { + if _, err := client.Update(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, update); err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } diff --git a/internal/services/compute/windows_virtual_machine_scale_set_resource_test.go b/internal/services/compute/windows_virtual_machine_scale_set_resource_test.go index 99e91170c717..9a9e32778a61 100644 --- a/internal/services/compute/windows_virtual_machine_scale_set_resource_test.go +++ b/internal/services/compute/windows_virtual_machine_scale_set_resource_test.go @@ -7,9 +7,9 @@ import ( "context" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -17,14 +17,14 @@ import ( type WindowsVirtualMachineScaleSetResource struct{} func (r WindowsVirtualMachineScaleSetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return nil, err } - resp, err := clients.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, "") + resp, err := clients.Compute.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, "") if err != nil { - return nil, fmt.Errorf("retrieving Compute Windows Virtual Machine Scale Set %q", id) + return nil, fmt.Errorf("retrieving Windows %s: %+v", id, err) } return utils.Bool(resp.ID != nil), nil diff --git a/internal/services/legacy/virtual_machine_scale_set_resource.go b/internal/services/legacy/virtual_machine_scale_set_resource.go index 6122a75d4d53..230110209321 100644 --- a/internal/services/legacy/virtual_machine_scale_set_resource.go +++ b/internal/services/legacy/virtual_machine_scale_set_resource.go @@ -17,7 +17,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" validate2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/services/legacy/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" @@ -49,7 +48,7 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource { DeprecationMessage: `The 'azurerm_virtual_machine_scale_set' resource has been superseded by the 'azurerm_linux_virtual_machine_scale_set' and 'azurerm_windows_virtual_machine_scale_set' resources. Whilst this resource will continue to be available in the 2.x and 3.x releases it is feature-frozen for compatibility purposes, will no longer receive any updates and will be removed in a future major release of the Azure Provider.`, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.VirtualMachineScaleSetID(id) + _, err := commonids.ParseVirtualMachineScaleSetID(id) return err }), @@ -814,11 +813,11 @@ func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta log.Printf("[INFO] preparing arguments for Azure ARM Virtual Machine Scale Set creation.") - id := parse.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := commonids.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { return fmt.Errorf("checking for presence of existing %s: %s", id, err) @@ -917,7 +916,7 @@ func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta } properties := compute.VirtualMachineScaleSet{ - Name: &id.Name, + Name: &id.VirtualMachineScaleSetName, Location: &location, Tags: tags.Expand(t), Sku: sku, @@ -937,7 +936,7 @@ func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta properties.Plan = expandAzureRmVirtualMachineScaleSetPlan(d) } - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, properties) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, properties) if err != nil { return err } @@ -956,24 +955,24 @@ func resourceVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta interfac ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := client.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] AzureRM Virtual Machine Scale Set (%s) Not Found. Removing from State", id.Name) + log.Printf("[INFO] %s was not found. Removing from State", id) d.SetId("") return nil } - return fmt.Errorf("making Read request on Azure Virtual Machine Scale Set %s: %+v", id.Name, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.VirtualMachineScaleSetName) + d.Set("resource_group_name", id.ResourceGroupName) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } @@ -1116,7 +1115,7 @@ func resourceVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta interf ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualMachineScaleSetID(d.Id()) + id, err := commonids.ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -1124,7 +1123,7 @@ func resourceVirtualMachineScaleSetDelete(d *pluginsdk.ResourceData, meta interf // @ArcturusZhang (mimicking from virtual_machine_pluginsdk.go): sending `nil` here omits this value from being sent // which matches the previous behaviour - we're only splitting this out so it's clear why var forceDeletion *bool = nil - future, err := client.Delete(ctx, id.ResourceGroup, id.Name, forceDeletion) + future, err := client.Delete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, forceDeletion) if err != nil { return err } diff --git a/internal/services/legacy/virtual_machine_scale_set_resource_test.go b/internal/services/legacy/virtual_machine_scale_set_resource_test.go index 8cf810cd734f..e50505ddd881 100644 --- a/internal/services/legacy/virtual_machine_scale_set_resource_test.go +++ b/internal/services/legacy/virtual_machine_scale_set_resource_test.go @@ -10,10 +10,10 @@ import ( "testing" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "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/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" "github.com/tombuildsstuff/kermit/sdk/compute/2023-03-01/compute" @@ -799,14 +799,14 @@ func TestAccVirtualMachineScaleSet_importBasic_managedDisk_withZones(t *testing. } func (VirtualMachineScaleSetResource) Destroy(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return nil, err } // this is a preview feature we don't want to use right now var forceDelete *bool = nil - future, err := client.Legacy.VMScaleSetClient.Delete(ctx, id.ResourceGroup, id.Name, forceDelete) + future, err := client.Legacy.VMScaleSetClient.Delete(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, forceDelete) if err != nil { return nil, fmt.Errorf("Bad: deleting %s: %+v", *id, err) } @@ -819,13 +819,13 @@ func (VirtualMachineScaleSetResource) Destroy(ctx context.Context, client *clien } func (VirtualMachineScaleSetResource) hasLoadBalancer(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - read, err := client.Legacy.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + read, err := client.Legacy.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return err } @@ -858,13 +858,13 @@ func (VirtualMachineScaleSetResource) hasLoadBalancer(ctx context.Context, clien } func (VirtualMachineScaleSetResource) hasApplicationGateway(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - read, err := client.Legacy.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + read, err := client.Legacy.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { return err } @@ -897,15 +897,15 @@ func (VirtualMachineScaleSetResource) hasApplicationGateway(ctx context.Context, } func (t VirtualMachineScaleSetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualMachineScaleSetID(state.ID) + id, err := commonids.ParseVirtualMachineScaleSetID(state.ID) if err != nil { return nil, err } // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := clients.Legacy.VMScaleSetClient.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) + resp, err := clients.Legacy.VMScaleSetClient.Get(ctx, id.ResourceGroupName, id.VirtualMachineScaleSetName, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { - return nil, fmt.Errorf("retrieving Compute Virtual Machine Scale Set %q", id) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } return utils.Bool(resp.ID != nil), nil diff --git a/internal/services/maintenance/maintenance_assignment_virtual_machine_scale_set_resource.go b/internal/services/maintenance/maintenance_assignment_virtual_machine_scale_set_resource.go index d819c7037327..930e28c06d06 100644 --- a/internal/services/maintenance/maintenance_assignment_virtual_machine_scale_set_resource.go +++ b/internal/services/maintenance/maintenance_assignment_virtual_machine_scale_set_resource.go @@ -8,14 +8,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/maintenance/2022-07-01-preview/configurationassignments" "github.com/hashicorp/go-azure-sdk/resource-manager/maintenance/2022-07-01-preview/maintenanceconfigurations" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - parseCompute "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" - validateCompute "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/services/maintenance/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" @@ -41,7 +40,7 @@ func resourceArmMaintenanceAssignmentVirtualMachineScaleSet() *pluginsdk.Resourc return err } - if _, err := parseCompute.VirtualMachineScaleSetID(parsed.Scope); err != nil { + if _, err := commonids.ParseVirtualMachineScaleSetID(parsed.Scope); err != nil { return fmt.Errorf("parsing %q as a Virtual Machine Scale Set ID: %+v", parsed.Scope, err) } @@ -68,7 +67,7 @@ func resourceArmMaintenanceAssignmentVirtualMachineScaleSet() *pluginsdk.Resourc Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateCompute.VirtualMachineScaleSetID, + ValidateFunc: commonids.ValidateVirtualMachineScaleSetID, DiffSuppressFunc: suppress.CaseDifference, // TODO remove in 4.0 }, }, @@ -80,7 +79,7 @@ func resourceArmMaintenanceAssignmentVirtualMachineScaleSetCreate(d *pluginsdk.R ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - virtualMachineScaleSetId, err := parseCompute.VirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) + virtualMachineScaleSetId, err := commonids.ParseVirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) if err != nil { return err } @@ -140,7 +139,7 @@ func resourceArmMaintenanceAssignmentVirtualMachineScaleSetRead(d *pluginsdk.Res return fmt.Errorf("checking for presence of existing %s: %+v", *id, err) } - virtualMachineScaleSetId, err := parseCompute.VirtualMachineScaleSetID(id.Scope) + virtualMachineScaleSetId, err := commonids.ParseVirtualMachineScaleSetID(id.Scope) if err != nil { return fmt.Errorf("parsing %q as a virtual machine scale set id: %+v", id.Scope, err) } diff --git a/internal/services/maintenance/migration/assignment_virtual_machine_scale_set_v0_to_v1.go b/internal/services/maintenance/migration/assignment_virtual_machine_scale_set_v0_to_v1.go index 053b3263730a..5f86f161118b 100644 --- a/internal/services/maintenance/migration/assignment_virtual_machine_scale_set_v0_to_v1.go +++ b/internal/services/maintenance/migration/assignment_virtual_machine_scale_set_v0_to_v1.go @@ -5,8 +5,8 @@ import ( "fmt" "log" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/maintenance/2022-07-01-preview/configurationassignments" - parseCompute "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -45,7 +45,7 @@ func (AssignmentVirtualMachineScaleSetV0ToV1) UpgradeFunc() pluginsdk.StateUpgra return nil, fmt.Errorf("parsing old id %q: %+v", oldIdRaw, err) } - virtualMachineScaleSetId, err := parseCompute.VirtualMachineScaleSetIDInsensitively(oldId.Scope) + virtualMachineScaleSetId, err := commonids.ParseVirtualMachineScaleSetIDInsensitively(oldId.Scope) if err != nil { return nil, fmt.Errorf("parsing %q as a virtual machine scale set id: %+v", oldId.Scope, err) } diff --git a/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set.go b/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set.go index ceaeec1a7d47..aa5dea430206 100644 --- a/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set.go +++ b/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set.go @@ -7,11 +7,11 @@ import ( "fmt" "regexp" - parseCompute "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" ) type MaintenanceAssignmentVirtualMachineScaleSetId struct { - VirtualMachineScaleSetId *parseCompute.VirtualMachineScaleSetId + VirtualMachineScaleSetId *commonids.VirtualMachineScaleSetId VirtualMachineScaleSetIdRaw string Name string } @@ -23,7 +23,7 @@ func MaintenanceAssignmentVirtualMachineScaleSetID(input string) (*MaintenanceAs } targetResourceId, name := groups[1], groups[2] - virtualMachineScaleSetId, err := parseCompute.VirtualMachineScaleSetID(targetResourceId) + virtualMachineScaleSetId, err := commonids.ParseVirtualMachineScaleSetIDInsensitively(targetResourceId) if err != nil { return nil, fmt.Errorf("parsing Maintenance Assignment Virtual Machine Scale Set ID: %q: Expected valid virtual machine scale set ID", input) } diff --git a/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set_test.go b/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set_test.go index 33155bb90d3f..3245bc1e27f9 100644 --- a/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set_test.go +++ b/internal/services/maintenance/parse/maintenance_assignment_virtual_machine_scale_set_test.go @@ -7,7 +7,7 @@ import ( "reflect" "testing" - parseCompute "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" ) func TestMaintenanceAssignmentVirtualMachineScaleSetID(t *testing.T) { @@ -58,10 +58,10 @@ func TestMaintenanceAssignmentVirtualMachineScaleSetID(t *testing.T) { Error: false, Expect: &MaintenanceAssignmentVirtualMachineScaleSetId{ VirtualMachineScaleSetIdRaw: "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/resGroup1/providers/microsoft.compute/virtualMachineScaleSets/vmss1", - VirtualMachineScaleSetId: &parseCompute.VirtualMachineScaleSetId{ - SubscriptionId: "00000000-0000-0000-0000-000000000000", - ResourceGroup: "resGroup1", - Name: "vmss1", + VirtualMachineScaleSetId: &commonids.VirtualMachineScaleSetId{ + SubscriptionId: "00000000-0000-0000-0000-000000000000", + ResourceGroupName: "resGroup1", + VirtualMachineScaleSetName: "vmss1", }, Name: "assign1", }, diff --git a/internal/services/network/virtual_machine_scale_set_packet_capture_resource.go b/internal/services/network/virtual_machine_scale_set_packet_capture_resource.go index 57fefe207c89..f33ac7a58414 100644 --- a/internal/services/network/virtual_machine_scale_set_packet_capture_resource.go +++ b/internal/services/network/virtual_machine_scale_set_packet_capture_resource.go @@ -16,7 +16,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" computeParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" - computeValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -61,7 +60,7 @@ func resourceVirtualMachineScaleSetPacketCapture() *pluginsdk.Resource { Required: true, ForceNew: true, ValidateFunc: validation.Any( - computeValidate.VirtualMachineScaleSetID, + commonids.ValidateVirtualMachineScaleSetID, ), }, diff --git a/internal/services/recoveryservices/site_recovery_replicated_vm_resource.go b/internal/services/recoveryservices/site_recovery_replicated_vm_resource.go index 4c8e6d5d3737..531538f052bb 100644 --- a/internal/services/recoveryservices/site_recovery_replicated_vm_resource.go +++ b/internal/services/recoveryservices/site_recovery_replicated_vm_resource.go @@ -31,8 +31,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" - computeParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" - computeValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/validate" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/recoveryservices/validate" @@ -287,7 +285,7 @@ func resourceSiteRecoveryReplicatedVM() *pluginsdk.Resource { "target_virtual_machine_scale_set_id": { Type: pluginsdk.TypeString, Optional: true, - ValidateFunc: computeValidate.VirtualMachineScaleSetID, + ValidateFunc: commonids.ValidateVirtualMachineScaleSetID, }, "network_interface": { @@ -816,7 +814,7 @@ func resourceSiteRecoveryReplicatedItemRead(d *pluginsdk.ResourceData, meta inte vmssId := "" if respVmssId := pointer.From(a2aDetails.RecoveryVirtualMachineScaleSetId); respVmssId != "" { - parsedVmssId, err := computeParse.VirtualMachineScaleSetIDInsensitively(respVmssId) + parsedVmssId, err := commonids.ParseVirtualMachineScaleSetIDInsensitively(respVmssId) if err != nil { return err }