From ed2a6238ef5ce7b4fb3e2c5132b698e8839c223f Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 13 Jan 2022 17:27:10 -0800 Subject: [PATCH] ID Parsers: compute resources (#14934) --- .../compute/availability_set_data_source.go | 13 +++-- .../compute/availability_set_resource.go | 15 +++-- .../dedicated_host_group_data_source.go | 17 +++--- .../compute/disk_access_data_source.go | 17 +++--- .../services/compute/disk_access_resource.go | 26 +++------ .../disk_encryption_set_data_source.go | 17 +++--- .../compute/disk_encryption_set_resource.go | 23 +++----- .../services/compute/image_data_source.go | 26 ++++----- internal/services/compute/image_resource.go | 22 +++----- .../compute/linux_virtual_machine_resource.go | 33 ++++------- ...inux_virtual_machine_scale_set_resource.go | 34 ++++-------- .../compute/managed_disk_data_source.go | 17 +++--- ...ated_virtual_machine_scale_set_resource.go | 55 ++++++++----------- .../proximity_placement_group_data_source.go | 2 +- .../proximity_placement_group_resource.go | 14 ++--- .../compute/shared_image_data_source.go | 20 +++---- .../shared_image_gallery_data_source.go | 17 +++--- .../compute/shared_image_gallery_resource.go | 26 +++------ .../services/compute/shared_image_resource.go | 27 +++------ .../shared_image_version_data_source.go | 17 +++--- .../compute/shared_image_version_resource.go | 23 +++----- .../services/compute/snapshot_data_source.go | 13 +++-- .../services/compute/snapshot_resource.go | 21 +++---- .../compute/ssh_public_key_data_source.go | 17 +++--- .../compute/ssh_public_key_resource.go | 25 +++------ .../compute/virtual_machine_data_source.go | 13 +++-- .../virtual_machine_extension_resource.go | 27 +++------ .../compute/virtual_machine_resource.go | 25 ++++----- .../virtual_machine_scale_set_data_source.go | 15 ++--- ...al_machine_scale_set_extension_resource.go | 22 +++----- .../virtual_machine_scale_set_resource.go | 23 +++----- .../windows_virtual_machine_resource.go | 33 ++++------- ...dows_virtual_machine_scale_set_resource.go | 35 ++++-------- 33 files changed, 299 insertions(+), 431 deletions(-) diff --git a/internal/services/compute/availability_set_data_source.go b/internal/services/compute/availability_set_data_source.go index a29c61c758b9..eff1f90566dc 100644 --- a/internal/services/compute/availability_set_data_source.go +++ b/internal/services/compute/availability_set_data_source.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -59,22 +60,22 @@ func dataSourceAvailabilitySet() *pluginsdk.Resource { func dataSourceAvailabilitySetRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.AvailabilitySetsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.NewAvailabilitySetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Availability Set %q (Resource Group %q) was not found", name, resGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("making Read request on Availability Set %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } diff --git a/internal/services/compute/availability_set_resource.go b/internal/services/compute/availability_set_resource.go index cb39796bcd8a..44a18dd5ab76 100644 --- a/internal/services/compute/availability_set_resource.go +++ b/internal/services/compute/availability_set_resource.go @@ -95,19 +95,18 @@ func resourceAvailabilitySet() *pluginsdk.Resource { func resourceAvailabilitySetCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.AvailabilitySetsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for AzureRM Availability Set creation.") - - name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + id := parse.NewAvailabilitySetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, resGroup, name) + existing, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Availability Set %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } @@ -123,7 +122,7 @@ func resourceAvailabilitySetCreateUpdate(d *pluginsdk.ResourceData, meta interfa t := d.Get("tags").(map[string]interface{}) availSet := compute.AvailabilitySet{ - Name: &name, + Name: &id.Name, Location: &location, AvailabilitySetProperties: &compute.AvailabilitySetProperties{ PlatformFaultDomainCount: utils.Int32(int32(faultDomainCount)), @@ -145,12 +144,12 @@ func resourceAvailabilitySetCreateUpdate(d *pluginsdk.ResourceData, meta interfa } } - resp, err := client.CreateOrUpdate(ctx, resGroup, name, availSet) + _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, availSet) if err != nil { return err } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceAvailabilitySetRead(d, meta) } diff --git a/internal/services/compute/dedicated_host_group_data_source.go b/internal/services/compute/dedicated_host_group_data_source.go index 657da47cdef8..e34ceb2c4376 100644 --- a/internal/services/compute/dedicated_host_group_data_source.go +++ b/internal/services/compute/dedicated_host_group_data_source.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -52,24 +53,24 @@ func dataSourceDedicatedHostGroup() *pluginsdk.Resource { func dataSourceDedicatedHostGroupRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.DedicatedHostGroupsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroupName := d.Get("resource_group_name").(string) + id := parse.NewDedicatedHostGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resourceGroupName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.HostGroupName, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Dedicated Host Group %q (Resource Group %q) was not found", name, resourceGroupName) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("reading Dedicated Host Group %q (Resource Group %q): %+v", name, resourceGroupName, err) + return fmt.Errorf("reading %s: %+v", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) - d.Set("name", name) - d.Set("resource_group_name", resourceGroupName) + d.Set("name", id.HostGroupName) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } diff --git a/internal/services/compute/disk_access_data_source.go b/internal/services/compute/disk_access_data_source.go index de80db73f982..f900ff2ade17 100644 --- a/internal/services/compute/disk_access_data_source.go +++ b/internal/services/compute/disk_access_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -35,24 +36,24 @@ func dataSourceDiskAccess() *pluginsdk.Resource { func dataSourceDiskAccessRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.DiskAccessClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.NewDiskAccessID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resourceGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Disk Access %q (Resource Group %q) was not found", name, resourceGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("Error: Error making Read request on Azure Disk Access %q (Resource Group %q): %s", name, resourceGroup, err) + return fmt.Errorf("making Read request on %s: %s", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) return tags.FlattenAndSet(d, resp.Tags) } diff --git a/internal/services/compute/disk_access_resource.go b/internal/services/compute/disk_access_resource.go index 703c4dc38ab9..136ef2acdd96 100644 --- a/internal/services/compute/disk_access_resource.go +++ b/internal/services/compute/disk_access_resource.go @@ -53,20 +53,20 @@ func resourceDiskAccess() *pluginsdk.Resource { func resourceDiskAccessCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.DiskAccessClient + subscriptionid := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for Azure ARM Disk Access creation.") - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewDiskAccessID(subscriptionid, d.Get("resource_group_name").(string), d.Get("name").(string)) t := d.Get("tags").(map[string]interface{}) if d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) + existing, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Disk Access %q (Resource Group %q): %s", name, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } if existing.ID != nil && *existing.ID != "" { @@ -77,29 +77,21 @@ func resourceDiskAccessCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) location := azure.NormalizeLocation(d.Get("location").(string)) createDiskAccess := compute.DiskAccess{ - Name: &name, + Name: &id.Name, Location: &location, Tags: tags.Expand(t), } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, createDiskAccess) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, createDiskAccess) if err != nil { - return fmt.Errorf("creating/updating Disk Access %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating/updating %s: %+v", id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for create/update of Disk Access %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting for create/update of %s: %+v", id, err) } - read, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("retrieving Disk Access %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if read.ID == nil { - return fmt.Errorf("reading Disk Access %s (Resource Group %q): ID was nil", name, resourceGroup) - } - - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceDiskAccessRead(d, meta) } diff --git a/internal/services/compute/disk_encryption_set_data_source.go b/internal/services/compute/disk_encryption_set_data_source.go index a7c2241cc78d..85e23969c648 100644 --- a/internal/services/compute/disk_encryption_set_data_source.go +++ b/internal/services/compute/disk_encryption_set_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -44,24 +45,24 @@ func dataSourceDiskEncryptionSet() *pluginsdk.Resource { func dataSourceDiskEncryptionSetRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.DiskEncryptionSetsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewDiskEncryptionSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resourceGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Disk Encryption Set %q (Resource Group %q) was not found", name, resourceGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("reading Disk Encryption Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("reading %s: %+v", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } diff --git a/internal/services/compute/disk_encryption_set_resource.go b/internal/services/compute/disk_encryption_set_resource.go index 12877d8b8b59..6e431257bc08 100644 --- a/internal/services/compute/disk_encryption_set_resource.go +++ b/internal/services/compute/disk_encryption_set_resource.go @@ -113,16 +113,16 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} client := meta.(*clients.Client).Compute.DiskEncryptionSetsClient keyVaultsClient := meta.(*clients.Client).KeyVault resourcesClient := meta.(*clients.Client).Resource + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewDiskEncryptionSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - existing, err := client.Get(ctx, resourceGroup, name) + existing, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for present of existing Disk Encryption Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for present of existing %s: %+v", id, err) } } if existing.ID != nil && *existing.ID != "" { @@ -163,22 +163,15 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} Tags: tags.Expand(t), } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, params) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, params) if err != nil { - return fmt.Errorf("creating Disk Encryption Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating %s: %+v", id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Disk Encryption Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting for creation of %s: %+v", id, err) } - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("retrieving Disk Encryption Set %q (Resource Group %q): %+v", name, resourceGroup, err) - } - if resp.ID == nil { - return fmt.Errorf("Cannot read Disk Encryption Set %q (Resource Group %q) ID", name, resourceGroup) - } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceDiskEncryptionSetRead(d, meta) } diff --git a/internal/services/compute/image_data_source.go b/internal/services/compute/image_data_source.go index 87e44b70693c..31132e258733 100644 --- a/internal/services/compute/image_data_source.go +++ b/internal/services/compute/image_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -123,15 +124,14 @@ func dataSourceImage() *pluginsdk.Resource { func dataSourceImageRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.ImagesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup := d.Get("resource_group_name").(string) - - name := d.Get("name").(string) + id := parse.NewImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) nameRegex, nameRegexOk := d.GetOk("name_regex") - if name == "" && !nameRegexOk { + if id.Name == "" && !nameRegexOk { return fmt.Errorf("[ERROR] either name or name_regex is required") } @@ -139,22 +139,22 @@ func dataSourceImageRead(d *pluginsdk.ResourceData, meta interface{}) error { if !nameRegexOk { var err error - if img, err = client.Get(ctx, resGroup, name, ""); err != nil { + if img, err = client.Get(ctx, id.ResourceGroup, id.Name, ""); err != nil { if utils.ResponseWasNotFound(img.Response) { - return fmt.Errorf("image %q was not found in resource group %q", name, resGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("[ERROR] Error making Read request on Azure Image %q (resource group %q): %+v", name, resGroup, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } } else { r := regexp.MustCompile(nameRegex.(string)) list := make([]compute.Image, 0) - resp, err := client.ListByResourceGroupComplete(ctx, resGroup) + resp, err := client.ListByResourceGroupComplete(ctx, id.ResourceGroup) if err != nil { if utils.ResponseWasNotFound(resp.Response().Response) { - return fmt.Errorf("No Images were found for Resource Group %q", resGroup) + return fmt.Errorf("no Images were found for Resource Group %q", id.ResourceGroup) } - return fmt.Errorf("[ERROR] Error getting list of images (resource group %q): %+v", resGroup, err) + return fmt.Errorf("getting list of images (resource group %q): %+v", id.ResourceGroup, err) } for resp.NotDone() { @@ -170,7 +170,7 @@ func dataSourceImageRead(d *pluginsdk.ResourceData, meta interface{}) error { } if 1 > len(list) { - return fmt.Errorf("No Images were found for Resource Group %q", resGroup) + return fmt.Errorf("no Images were found for Resource Group %q", id.ResourceGroup) } if len(list) > 1 { @@ -185,9 +185,9 @@ func dataSourceImageRead(d *pluginsdk.ResourceData, meta interface{}) error { img = list[0] } - d.SetId(*img.ID) + d.SetId(id.ID()) d.Set("name", img.Name) - d.Set("resource_group_name", resGroup) + d.Set("resource_group_name", id.ResourceGroup) if location := img.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 021ed938ea3d..48b8dcaa7dd3 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -190,21 +190,21 @@ func resourceImage() *pluginsdk.Resource { func resourceImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.ImagesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for AzureRM Image creation.") - name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + id := parse.NewImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) zoneResilient := d.Get("zone_resilient").(bool) hyperVGeneration := d.Get("hyper_v_generation").(string) if d.IsNewResource() { - existing, err := client.Get(ctx, resGroup, name, "") + existing, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Image %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } @@ -248,13 +248,13 @@ func resourceImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) erro } createImage := compute.Image{ - Name: &name, + Name: &id.Name, Location: &location, Tags: expandedTags, ImageProperties: &properties, } - future, err := client.CreateOrUpdate(ctx, resGroup, name, createImage) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, createImage) if err != nil { return err } @@ -263,15 +263,7 @@ func resourceImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) erro return err } - read, err := client.Get(ctx, resGroup, name, "") - if err != nil { - return err - } - if read.ID == nil { - return fmt.Errorf("[ERROR] Cannot read AzureRM Image %s (resource group %s) ID", name, resGroup) - } - - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceImageRead(d, meta) } diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index 8fa318aa7bd1..b60ad688cdad 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -329,19 +329,19 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource { func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewVirtualMachineID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - locks.ByName(name, virtualMachineResourceName) - defer locks.UnlockByName(name, virtualMachineResourceName) + locks.ByName(id.Name, virtualMachineResourceName) + defer locks.UnlockByName(id.Name, virtualMachineResourceName) - resp, err := client.Get(ctx, resourceGroup, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("checking for existing Linux Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for existing %s: %+v", id, err) } } @@ -366,7 +366,7 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface if len(errs) > 0 { return fmt.Errorf("unable to assume default computer name %s Please adjust the %q, or specify an explicit %q", errs[0], "name", "computer_name") } - computerName = name + computerName = id.Name } disablePasswordAuthentication := d.Get("disable_password_authentication").(bool) location := azure.NormalizeLocation(d.Get("location").(string)) @@ -402,7 +402,7 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface sshKeys := ExpandSSHKeys(sshKeysRaw) params := compute.VirtualMachine{ - Name: utils.String(name), + Name: utils.String(id.Name), Location: utils.String(location), Identity: identity, Plan: plan, @@ -561,25 +561,16 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface params.OsProfile.AdminPassword = utils.String(adminPassword) } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, params) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, params) if err != nil { - return fmt.Errorf("creating Linux Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating Linux %s: %+v", id, err) } if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Linux Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - read, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - return fmt.Errorf("retrieving Linux Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if read.ID == nil { - return fmt.Errorf("retrieving Linux Virtual Machine %q (Resource Group %q): `id` was nil", name, resourceGroup) + return fmt.Errorf("waiting for creation of Linux %s: %+v", id, err) } - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceLinuxVirtualMachineRead(d, meta) } 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 ba3c53b4ab20..78d82e4f44aa 100644 --- a/internal/services/compute/linux_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/linux_virtual_machine_scale_set_resource.go @@ -294,17 +294,17 @@ func resourceLinuxVirtualMachineScaleSet() *pluginsdk.Resource { func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMScaleSetClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.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, resourceGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) + exists, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if !utils.ResponseWasNotFound(exists.Response) { - return fmt.Errorf("checking for existing Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for existing Linux %s: %+v", id, err) } } @@ -390,7 +390,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 = name + computerNamePrefix = id.Name } disablePasswordAuthentication := d.Get("disable_password_authentication").(bool) @@ -575,29 +575,19 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i props.VirtualMachineScaleSetProperties.ZoneBalance = utils.Bool(v.(bool)) } - log.Printf("[DEBUG] Creating Linux Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup) - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, props) + log.Printf("[DEBUG] Creating Linux %s", id) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) if err != nil { - return fmt.Errorf("creating Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating Linux %s: %+v", id, err) } - log.Printf("[DEBUG] Waiting for Linux Virtual Machine Scale Set %q (Resource Group %q) to be created..", name, resourceGroup) + log.Printf("[DEBUG] Waiting for Linux %s to be created..", id) if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting for creation of Linux %s: %+v", id, err) } - log.Printf("[DEBUG] Virtual Machine Scale Set %q (Resource Group %q) was created", name, resourceGroup) + log.Printf("[DEBUG] %s was created", id) - log.Printf("[DEBUG] Retrieving Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup) - // Upgrading to the 2021-07-01 exposed a new expand parameter to the GET method - resp, err := client.Get(ctx, resourceGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) - if err != nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if resp.ID == nil { - return fmt.Errorf("retrieving Linux Virtual Machine Scale Set %q (Resource Group %q): ID was nil", name, resourceGroup) - } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceLinuxVirtualMachineScaleSetRead(d, meta) } diff --git a/internal/services/compute/managed_disk_data_source.go b/internal/services/compute/managed_disk_data_source.go index d9a0b0c1203e..4f85a442730a 100644 --- a/internal/services/compute/managed_disk_data_source.go +++ b/internal/services/compute/managed_disk_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -93,24 +94,24 @@ func dataSourceManagedDisk() *pluginsdk.Resource { func dataSourceManagedDiskRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.DisksClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.NewManagedDiskID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.DiskName) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Managed Disk %q (Resource Group %q) was not found", name, resGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("[ERROR] Error making Read request on Azure Managed Disk %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("making Read request on %s: %s", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) - d.Set("name", name) - d.Set("resource_group_name", resGroup) + d.Set("name", id.DiskName) + d.Set("resource_group_name", id.ResourceGroup) if sku := resp.Sku; sku != nil { d.Set("storage_account_type", string(sku.Name)) 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 5eca440ccc67..5fefd0dc47b5 100644 --- a/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/orchestrated_virtual_machine_scale_set_resource.go @@ -199,19 +199,19 @@ func resourceOrchestratedVirtualMachineScaleSet() *pluginsdk.Resource { func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMScaleSetClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() isLegacy := true - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.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, resourceGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for existing Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for existing %s: %+v", id, err) } } @@ -291,11 +291,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(name, "computer_name_prefix") + _, errs := computeValidate.WindowsComputerNamePrefix(id.Name, "computer_name_prefix") 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") } - vmssOsProfile.ComputerNamePrefix = utils.String(name) + vmssOsProfile.ComputerNamePrefix = utils.String(id.Name) } } @@ -307,11 +307,11 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, // if the Computer Prefix Name was not defined use the computer name if len(*vmssOsProfile.ComputerNamePrefix) == 0 { // validate that the computer name is a valid Computer Prefix Name - _, errs := computeValidate.LinuxComputerNamePrefix(name, "computer_name_prefix") + _, errs := computeValidate.LinuxComputerNamePrefix(id.Name, "computer_name_prefix") 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") } - vmssOsProfile.ComputerNamePrefix = utils.String(name) + vmssOsProfile.ComputerNamePrefix = utils.String(id.Name) } } @@ -380,7 +380,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", name, resourceGroup) + log.Printf("[DEBUG] Orchestrated %s has a Health Extension defined", id) } if v, ok := d.Get("max_bid_price").(float64); ok && v > 0 { @@ -445,36 +445,36 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, props.VirtualMachineScaleSetProperties.VirtualMachineProfile = &virtualMachineProfile } - log.Printf("[DEBUG] Creating Orchestrated Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup) - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, props) + log.Printf("[DEBUG] Creating Orchestrated %s.", id) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) if err != nil { - return fmt.Errorf("creating Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating Orchestrated %s: %+v", id, err) } - log.Printf("[DEBUG] Waiting for Orchestrated Virtual Machine Scale Set %q (Resource Group %q) to be created..", name, resourceGroup) + log.Printf("[DEBUG] Waiting for %s to be created.", id) if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { // If it is a Retryable Error re-issue the PUT for 10 loops until either the error goes away or the limit has been reached if strings.Contains(err.Error(), "RetryableError") { - log.Printf("[DEBUG] Retryable error hit for Orchestrated Virtual Machine Scale Set %q (Resource Group %q) to be created..", name, resourceGroup) + log.Printf("[DEBUG] Retryable error hit for %s to be created..", id) errCount := 1 for { - log.Printf("[DEBUG] Retrying PUT %d for Orchestrated Virtual Machine Scale Set %q (Resource Group %q)..", errCount, name, resourceGroup) - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, props) + log.Printf("[DEBUG] Retrying PUT %d for Orchestrated %s.", errCount, id) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) if err != nil { - return fmt.Errorf("creating Orchestrated Virtual Machine Scale Set %q (Resource Group %q) after %d retries: %+v", name, resourceGroup, errCount, err) + return fmt.Errorf("creating Orchestrated %s after %d retries: %+v", id, errCount, err) } err = future.WaitForCompletionRef(ctx, client.Client) if err != nil && strings.Contains(err.Error(), "RetryableError") { if errCount == 10 { - return fmt.Errorf("waiting for creation of Orchestrated Virtual Machine Scale Set %q (Resource Group %q) after %d retries: %+v", name, resourceGroup, err, errCount) + return fmt.Errorf("waiting for creation of Orchestrated %s after %d retries: %+v", id, err, errCount) } errCount++ } else { if err != nil { // Hit an error while retying that is not retryable anymore... - return fmt.Errorf("hit unretryable error waiting for creation of Orchestrated Virtual Machine Scale Set %q (Resource Group %q) after %d retries: %+v", name, resourceGroup, err, errCount) + return fmt.Errorf("hit unretryable error waiting for creation of Orchestrated %s after %d retries: %+v", id, err, errCount) } else { // err is nil and finally succeeded continue with the rest of the create function... break @@ -483,23 +483,14 @@ func resourceOrchestratedVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, } } else { // Not a retryable error... - return fmt.Errorf("waiting for creation of Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting for creation of Orchestrated %s: %+v", id, err) } } - log.Printf("[DEBUG] Orchestrated Virtual Machine Scale Set %q (Resource Group %q) was created", name, resourceGroup) - log.Printf("[DEBUG] Retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup) + log.Printf("[DEBUG] Orchestrated %s was created", id) + log.Printf("[DEBUG] Retrieving Orchestrated %s.", id) - // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Get(ctx, resourceGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) - if err != nil { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if resp.ID == nil || *resp.ID == "" { - return fmt.Errorf("retrieving Orchestrated Virtual Machine Scale Set %q (Resource Group %q): ID was nil", name, resourceGroup) - } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceOrchestratedVirtualMachineScaleSetRead(d, meta) } diff --git a/internal/services/compute/proximity_placement_group_data_source.go b/internal/services/compute/proximity_placement_group_data_source.go index 0a09f846dd69..8b12174b45c6 100644 --- a/internal/services/compute/proximity_placement_group_data_source.go +++ b/internal/services/compute/proximity_placement_group_data_source.go @@ -55,7 +55,7 @@ func dataSourceProximityPlacementGroupRead(d *pluginsdk.ResourceData, meta inter return fmt.Errorf("making Read request on %s: %+v", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) diff --git a/internal/services/compute/proximity_placement_group_resource.go b/internal/services/compute/proximity_placement_group_resource.go index 9932685aebc4..8a29600cd6c8 100644 --- a/internal/services/compute/proximity_placement_group_resource.go +++ b/internal/services/compute/proximity_placement_group_resource.go @@ -55,19 +55,19 @@ func resourceProximityPlacementGroup() *pluginsdk.Resource { func resourceProximityPlacementGroupCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.ProximityPlacementGroupsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for AzureRM Proximity Placement Group creation.") - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewProximityPlacementGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name, "") + existing, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Proximity Placement Group %q (Resource Group %q): %s", name, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } @@ -77,17 +77,17 @@ func resourceProximityPlacementGroupCreateUpdate(d *pluginsdk.ResourceData, meta } ppg := compute.ProximityPlacementGroup{ - Name: &name, + Name: &id.Name, Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } - resp, err := client.CreateOrUpdate(ctx, resourceGroup, name, ppg) + _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, ppg) if err != nil { return err } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceProximityPlacementGroupRead(d, meta) } diff --git a/internal/services/compute/shared_image_data_source.go b/internal/services/compute/shared_image_data_source.go index 3db4b74f916d..60df8aad3e7e 100644 --- a/internal/services/compute/shared_image_data_source.go +++ b/internal/services/compute/shared_image_data_source.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -102,27 +103,26 @@ func dataSourceSharedImage() *pluginsdk.Resource { func dataSourceSharedImageRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImagesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - galleryName := d.Get("gallery_name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSharedImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resourceGroup, galleryName, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Shared Image %q was not found in Gallery %q / Resource Group %q", name, galleryName, resourceGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("making Read request on Shared Image %q (Gallery %q / Resource Group %q): %+v", name, galleryName, resourceGroup, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) - d.Set("name", name) - d.Set("gallery_name", galleryName) - d.Set("resource_group_name", resourceGroup) + d.Set("name", id.ImageName) + d.Set("gallery_name", id.GalleryName) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } diff --git a/internal/services/compute/shared_image_gallery_data_source.go b/internal/services/compute/shared_image_gallery_data_source.go index 521cd249eefa..de4fa764a2ee 100644 --- a/internal/services/compute/shared_image_gallery_data_source.go +++ b/internal/services/compute/shared_image_gallery_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -49,25 +50,25 @@ func dataSourceSharedImageGallery() *pluginsdk.Resource { func dataSourceSharedImageGalleryRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleriesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSharedImageGalleryID(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, resourceGroup, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Shared Image Gallery %q (Resource Group %q) was not found", name, resourceGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("making Read request on Shared Image Gallery %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } - d.SetId(*resp.ID) - d.Set("name", name) - d.Set("resource_group_name", resourceGroup) + d.SetId(id.ID()) + d.Set("name", id.GalleryName) + d.Set("resource_group_name", id.ResourceGroup) if location := resp.Location; location != nil { d.Set("location", azure.NormalizeLocation(*location)) } diff --git a/internal/services/compute/shared_image_gallery_resource.go b/internal/services/compute/shared_image_gallery_resource.go index 1736baf4eea3..0e4863585c52 100644 --- a/internal/services/compute/shared_image_gallery_resource.go +++ b/internal/services/compute/shared_image_gallery_resource.go @@ -65,23 +65,23 @@ func resourceSharedImageGallery() *pluginsdk.Resource { func resourceSharedImageGalleryCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleriesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for Image Gallery creation.") - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSharedImageGalleryID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) location := azure.NormalizeLocation(d.Get("location").(string)) description := d.Get("description").(string) t := d.Get("tags").(map[string]interface{}) if d.IsNewResource() { // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - existing, err := client.Get(ctx, resourceGroup, name, "") + existing, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Shared Image Gallery %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } @@ -98,26 +98,16 @@ func resourceSharedImageGalleryCreateUpdate(d *pluginsdk.ResourceData, meta inte Tags: tags.Expand(t), } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, gallery) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.GalleryName, gallery) if err != nil { - return fmt.Errorf("creating/updating Shared Image Gallery %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating/updating %s: %+v", id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation/update of Shared Image Gallery %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting for creation/update of %s: %+v", id, err) } - // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - read, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - return fmt.Errorf("retrieving Shared Image Gallery %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if read.ID == nil { - return fmt.Errorf("Cannot read Shared Image Gallery %q (Resource Group %q) ID", name, resourceGroup) - } - - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceSharedImageGalleryRead(d, meta) } diff --git a/internal/services/compute/shared_image_resource.go b/internal/services/compute/shared_image_resource.go index 823585acdfd4..a2f37970ba57 100644 --- a/internal/services/compute/shared_image_resource.go +++ b/internal/services/compute/shared_image_resource.go @@ -167,20 +167,18 @@ func resourceSharedImage() *pluginsdk.Resource { func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImagesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for Shared Image creation.") - - name := d.Get("name").(string) - galleryName := d.Get("gallery_name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSharedImageID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, galleryName, name) + existing, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Shared Image %q (Gallery %q / Resource Group %q): %+v", name, galleryName, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } @@ -219,25 +217,16 @@ func resourceSharedImageCreateUpdate(d *pluginsdk.ResourceData, meta interface{} image.GalleryImageProperties.OsState = compute.OperatingSystemStateTypesGeneralized } - future, err := client.CreateOrUpdate(ctx, resourceGroup, galleryName, name, image) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, image) if err != nil { - return fmt.Errorf("creating/updating Shared Image %q (Gallery %q / Resource Group %q): %+v", name, galleryName, resourceGroup, err) + return fmt.Errorf("creating/updating %s: %+v", id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation/update of Shared Image %q (Gallery %q / Resource Group %q): %+v", name, galleryName, resourceGroup, err) - } - - read, err := client.Get(ctx, resourceGroup, galleryName, name) - if err != nil { - return fmt.Errorf("retrieving Shared Image %q (Gallery %q / Resource Group %q): %+v", name, galleryName, resourceGroup, err) - } - - if read.ID == nil { - return fmt.Errorf("Cannot read Shared Image %q (Gallery %q / Resource Group %q) ID", name, galleryName, resourceGroup) + return fmt.Errorf("waiting for creation/update of %s: %+v", id, err) } - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceSharedImageRead(d, meta) } diff --git a/internal/services/compute/shared_image_version_data_source.go b/internal/services/compute/shared_image_version_data_source.go index eebde51700a7..9d36735af87f 100644 --- a/internal/services/compute/shared_image_version_data_source.go +++ b/internal/services/compute/shared_image_version_data_source.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -102,25 +103,23 @@ func dataSourceSharedImageVersion() *pluginsdk.Resource { func dataSourceSharedImageVersionRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImageVersionsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - imageVersion := d.Get("name").(string) - imageName := d.Get("image_name").(string) - galleryName := d.Get("gallery_name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSharedImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) sortBySemVer := d.Get("sort_versions_by_semver").(bool) - image, err := obtainImage(client, ctx, resourceGroup, galleryName, imageName, imageVersion, sortBySemVer) + image, err := obtainImage(client, ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, sortBySemVer) if err != nil { return err } - d.SetId(*image.ID) + d.SetId(id.ID()) d.Set("name", image.Name) - d.Set("image_name", imageName) - d.Set("gallery_name", galleryName) - d.Set("resource_group_name", resourceGroup) + d.Set("image_name", id.ImageName) + d.Set("gallery_name", id.GalleryName) + d.Set("resource_group_name", id.ResourceGroup) d.Set("sort_versions_by_semver", sortBySemVer) if location := image.Location; location != nil { diff --git a/internal/services/compute/shared_image_version_resource.go b/internal/services/compute/shared_image_version_resource.go index e1193e4cf173..d599a5faa74c 100644 --- a/internal/services/compute/shared_image_version_resource.go +++ b/internal/services/compute/shared_image_version_resource.go @@ -131,19 +131,17 @@ func resourceSharedImageVersion() *pluginsdk.Resource { func resourceSharedImageVersionCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.GalleryImageVersionsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - imageVersion := d.Get("name").(string) - imageName := d.Get("image_name").(string) - galleryName := d.Get("gallery_name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSharedImageVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("gallery_name").(string), d.Get("image_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, galleryName, imageName, imageVersion, "") + existing, err := client.Get(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", imageVersion, imageName, galleryName, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } @@ -178,21 +176,16 @@ func resourceSharedImageVersionCreateUpdate(d *pluginsdk.ResourceData, meta inte } } - future, err := client.CreateOrUpdate(ctx, resourceGroup, galleryName, imageName, imageVersion, version) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.GalleryName, id.ImageName, id.VersionName, version) if err != nil { - return fmt.Errorf("creating Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", imageVersion, imageName, galleryName, resourceGroup, err) + return fmt.Errorf("creating %s: %+v", id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the creation of Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", imageVersion, imageName, galleryName, resourceGroup, err) + return fmt.Errorf("waiting for the creation of %s: %+v", id, err) } - read, err := client.Get(ctx, resourceGroup, galleryName, imageName, imageVersion, "") - if err != nil { - return fmt.Errorf("retrieving Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", imageVersion, imageName, galleryName, resourceGroup, err) - } - - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceSharedImageVersionRead(d, meta) } diff --git a/internal/services/compute/snapshot_data_source.go b/internal/services/compute/snapshot_data_source.go index d584e0a5511a..07054c6d18ac 100644 --- a/internal/services/compute/snapshot_data_source.go +++ b/internal/services/compute/snapshot_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -109,21 +110,21 @@ func dataSourceSnapshot() *pluginsdk.Resource { func dataSourceSnapshotRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.SnapshotsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.NewSnapshotID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resourceGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Snapshot %q (Resource Group %q) was not found", name, resourceGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("loading Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("loading %s: %+v", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) if props := resp.SnapshotProperties; props != nil { d.Set("os_type", string(props.OsType)) diff --git a/internal/services/compute/snapshot_resource.go b/internal/services/compute/snapshot_resource.go index db1121e4ee35..c0b744ff97f5 100644 --- a/internal/services/compute/snapshot_resource.go +++ b/internal/services/compute/snapshot_resource.go @@ -93,20 +93,20 @@ func resourceSnapshot() *pluginsdk.Resource { func resourceSnapshotCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.SnapshotsClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSnapshotID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) location := azure.NormalizeLocation(d.Get("location").(string)) createOption := d.Get("create_option").(string) t := d.Get("tags").(map[string]interface{}) if d.IsNewResource() { - existing, err := client.Get(ctx, resourceGroup, name) + existing, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } } @@ -148,21 +148,16 @@ func resourceSnapshotCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) e properties.EncryptionSettingsCollection = expandManagedDiskEncryptionSettings(settings) } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, properties) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, properties) if err != nil { - return fmt.Errorf("issuing create/update request for Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("issuing create/update request for %s: %+v", id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting on create/update future for Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting on create/update future for %s: %+v", id, err) } - resp, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("issuing get request for Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceSnapshotRead(d, meta) } diff --git a/internal/services/compute/ssh_public_key_data_source.go b/internal/services/compute/ssh_public_key_data_source.go index 903efe073fa5..789e15baf750 100644 --- a/internal/services/compute/ssh_public_key_data_source.go +++ b/internal/services/compute/ssh_public_key_data_source.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -47,24 +48,24 @@ func dataSourceSshPublicKey() *pluginsdk.Resource { func dataSourceSshPublicKeyRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.SSHPublicKeysClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.NewSSHPublicKeyID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("SSH Public Key %q (Resource Group %q) was not found", name, resGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("making Read request on Azure SSH Public Key %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("making Read request on %s: %s", id, err) } - d.SetId(*resp.ID) + d.SetId(id.ID()) - d.Set("name", name) - d.Set("resource_group_name", resGroup) + d.Set("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) var publicKey *string if props := resp.SSHPublicKeyResourceProperties; props.PublicKey != nil { diff --git a/internal/services/compute/ssh_public_key_resource.go b/internal/services/compute/ssh_public_key_resource.go index 7b0edfb552db..c2f1e9d97edb 100644 --- a/internal/services/compute/ssh_public_key_resource.go +++ b/internal/services/compute/ssh_public_key_resource.go @@ -70,17 +70,17 @@ func resourceSshPublicKey() *pluginsdk.Resource { func resourceSshPublicKeyCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.SSHPublicKeysClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewSSHPublicKeyID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) public_key := d.Get("public_key").(string) - resp, err := client.Get(ctx, resourceGroup, name) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) if err != nil { if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("checking for existing SSH Public Key %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for existing %s: %+v", id, err) } } @@ -93,7 +93,7 @@ func resourceSshPublicKeyCreate(d *pluginsdk.ResourceData, meta interface{}) err t := d.Get("tags").(map[string]interface{}) params := compute.SSHPublicKeyResource{ - Name: utils.String(name), + Name: utils.String(id.Name), Location: utils.String(location), Tags: tags.Expand(t), SSHPublicKeyResourceProperties: &compute.SSHPublicKeyResourceProperties{ @@ -101,20 +101,11 @@ func resourceSshPublicKeyCreate(d *pluginsdk.ResourceData, meta interface{}) err }, } - if _, err := client.Create(ctx, resourceGroup, name, params); err != nil { - return fmt.Errorf("creating SSH Public Key %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - read, err := client.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("retrieving SSH Public Key %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if read.ID == nil { - return fmt.Errorf("retrieving SSH Public Key %q (Resource Group %q): `id` was nil", name, resourceGroup) + if _, err := client.Create(ctx, id.ResourceGroup, id.Name, params); err != nil { + return fmt.Errorf("creating SSH Public Key %s: %+v", id, err) } - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceSshPublicKeyRead(d, meta) } diff --git a/internal/services/compute/virtual_machine_data_source.go b/internal/services/compute/virtual_machine_data_source.go index 26f317895190..6289efcad5b8 100644 --- a/internal/services/compute/virtual_machine_data_source.go +++ b/internal/services/compute/virtual_machine_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -89,22 +90,22 @@ func dataSourceVirtualMachine() *pluginsdk.Resource { func dataSourceVirtualMachineRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId networkInterfacesClient := meta.(*clients.Client).Network.InterfacesClient publicIPAddressesClient := meta.(*clients.Client).Network.PublicIPsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.NewVirtualMachineID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, resGroup, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Virtual Machine %q (Resource Group %q) was not found", name, resGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("making Read request on Virtual Machine %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } connectionInfo := retrieveConnectionInformation(ctx, networkInterfacesClient, publicIPAddressesClient, resp.VirtualMachineProperties) @@ -124,7 +125,7 @@ func dataSourceVirtualMachineRead(d *pluginsdk.ResourceData, meta interface{}) e if err != nil { return err } - d.SetId(*resp.ID) + d.SetId(id.ID()) identity, err := flattenVirtualMachineIdentity(resp.Identity) if err != nil { diff --git a/internal/services/compute/virtual_machine_extension_resource.go b/internal/services/compute/virtual_machine_extension_resource.go index c7463d1af46b..77a77ff8bab7 100644 --- a/internal/services/compute/virtual_machine_extension_resource.go +++ b/internal/services/compute/virtual_machine_extension_resource.go @@ -102,29 +102,27 @@ func resourceVirtualMachineExtensionsCreateUpdate(d *pluginsdk.ResourceData, met ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) virtualMachineId, err := parse.VirtualMachineID(d.Get("virtual_machine_id").(string)) if err != nil { return fmt.Errorf("parsing Virtual Machine ID %q: %+v", virtualMachineId, err) } - virtualMachineName := virtualMachineId.Name - resourceGroup := virtualMachineId.ResourceGroup + id := parse.NewVirtualMachineExtensionID(virtualMachineId.SubscriptionId, virtualMachineId.ResourceGroup, virtualMachineId.Name, d.Get("name").(string)) - virtualMachine, err := vmClient.Get(ctx, resourceGroup, virtualMachineName, "") + virtualMachine, err := vmClient.Get(ctx, id.ResourceGroup, id.VirtualMachineName, "") if err != nil { - return fmt.Errorf("getting Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("getting %s: %+v", virtualMachineId, err) } location := *virtualMachine.Location if location == "" { - return fmt.Errorf("reading location of Virtual Machine %q", virtualMachineName) + return fmt.Errorf("reading location of %s", virtualMachineId) } if d.IsNewResource() { - existing, err := vmExtensionClient.Get(ctx, resourceGroup, virtualMachineName, name, "") + existing, err := vmExtensionClient.Get(ctx, id.ResourceGroup, id.VirtualMachineName, id.ExtensionName, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Extension %q (Virtual Machine %q / Resource Group %q): %s", name, virtualMachineName, resourceGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } @@ -168,7 +166,7 @@ func resourceVirtualMachineExtensionsCreateUpdate(d *pluginsdk.ResourceData, met extension.VirtualMachineExtensionProperties.ProtectedSettings = &protectedSettings } - future, err := vmExtensionClient.CreateOrUpdate(ctx, resourceGroup, virtualMachineName, name, extension) + future, err := vmExtensionClient.CreateOrUpdate(ctx, id.ResourceGroup, id.VirtualMachineName, id.ExtensionName, extension) if err != nil { return err } @@ -177,16 +175,7 @@ func resourceVirtualMachineExtensionsCreateUpdate(d *pluginsdk.ResourceData, met return err } - read, err := vmExtensionClient.Get(ctx, resourceGroup, virtualMachineName, name, "") - if err != nil { - return err - } - - if read.ID == nil { - return fmt.Errorf("Cannot read Virtual Machine Extension %s (resource group %s) ID", name, resourceGroup) - } - - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceVirtualMachineExtensionsRead(d, meta) } diff --git a/internal/services/compute/virtual_machine_resource.go b/internal/services/compute/virtual_machine_resource.go index 3d1aa0025eb1..2af15b5447ab 100644 --- a/internal/services/compute/virtual_machine_resource.go +++ b/internal/services/compute/virtual_machine_resource.go @@ -631,19 +631,18 @@ func resourceVirtualMachine() *pluginsdk.Resource { func resourceVirtualMachineCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for Azure ARM Virtual Machine creation.") - - name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + id := parse.NewVirtualMachineID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, resGroup, name, "") + existing, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Virtual Machine %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } @@ -730,7 +729,7 @@ func resourceVirtualMachineCreateUpdate(d *pluginsdk.ResourceData, meta interfac } vm := compute.VirtualMachine{ - Name: &name, + Name: &id.Name, Location: &location, VirtualMachineProperties: &properties, Tags: expandedTags, @@ -745,10 +744,10 @@ func resourceVirtualMachineCreateUpdate(d *pluginsdk.ResourceData, meta interfac vm.Plan = expandAzureRmVirtualMachinePlan(d) } - locks.ByName(name, virtualMachineResourceName) - defer locks.UnlockByName(name, virtualMachineResourceName) + locks.ByName(id.Name, virtualMachineResourceName) + defer locks.UnlockByName(id.Name, virtualMachineResourceName) - future, err := client.CreateOrUpdate(ctx, resGroup, name, vm) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, vm) if err != nil { return err } @@ -757,19 +756,19 @@ func resourceVirtualMachineCreateUpdate(d *pluginsdk.ResourceData, meta interfac return err } - read, err := client.Get(ctx, resGroup, name, "") + read, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { return err } if read.ID == nil { - return fmt.Errorf("Cannot read Virtual Machine %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("cannot read %s", id) } - d.SetId(*read.ID) + d.SetId(id.ID()) ipAddress, err := determineVirtualMachineIPAddress(ctx, meta, read.VirtualMachineProperties) if err != nil { - return fmt.Errorf("determining IP Address for Virtual Machine %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("determining IP Address for %s: %+v", id, err) } provisionerType := "ssh" 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 6f689aab8e63..80af5dba8bc2 100644 --- a/internal/services/compute/virtual_machine_scale_set_data_source.go +++ b/internal/services/compute/virtual_machine_scale_set_data_source.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "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/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -64,26 +65,26 @@ func dataSourceVirtualMachineScaleSet() *pluginsdk.Resource { func dataSourceVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMScaleSetClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) + id := parse.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, resGroup, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Error: Virtual Machine Scale Set %q (Resource Group %q) was not found", name, resGroup) + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("making Read request on Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("making Read request on %s: %+v", id, err) } if resp.ID == nil || *resp.ID == "" { - return fmt.Errorf("reading Virtual Machine Scale Set %q (Resource Group %q): ID is empty or nil", name, resGroup) + return fmt.Errorf("reading %s: ID is empty or nil", id) } - d.SetId(*resp.ID) + d.SetId(id.ID()) if profile := resp.VirtualMachineProfile; profile != nil { if nwProfile := profile.NetworkProfile; nwProfile != nil { 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 2d8ab918377d..bae0780e34bc 100644 --- a/internal/services/compute/virtual_machine_scale_set_extension_resource.go +++ b/internal/services/compute/virtual_machine_scale_set_extension_resource.go @@ -119,18 +119,16 @@ func resourceVirtualMachineScaleSetExtensionCreate(d *pluginsdk.ResourceData, me ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) virtualMachineScaleSetId, err := parse.VirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) if err != nil { return err } - resourceGroup := virtualMachineScaleSetId.ResourceGroup - vmssName := virtualMachineScaleSetId.Name + id := parse.NewVirtualMachineScaleSetExtensionID(virtualMachineScaleSetId.SubscriptionId, virtualMachineScaleSetId.ResourceGroup, virtualMachineScaleSetId.Name, d.Get("name").(string)) - resp, err := client.Get(ctx, resourceGroup, vmssName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.VirtualMachineScaleSetName, id.ExtensionName, "") if err != nil { if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("checking for existing Extension %q (Virtual Machine Scale Set %q / Resource Group %q): %+v", name, vmssName, resourceGroup, err) + return fmt.Errorf("checking for existing %s: %+v", id, err) } } @@ -160,7 +158,7 @@ func resourceVirtualMachineScaleSetExtensionCreate(d *pluginsdk.ResourceData, me } props := compute.VirtualMachineScaleSetExtension{ - Name: utils.String(name), + Name: utils.String(id.ExtensionName), VirtualMachineScaleSetExtensionProperties: &compute.VirtualMachineScaleSetExtensionProperties{ Publisher: utils.String(d.Get("publisher").(string)), Type: utils.String(d.Get("type").(string)), @@ -176,20 +174,16 @@ func resourceVirtualMachineScaleSetExtensionCreate(d *pluginsdk.ResourceData, me props.VirtualMachineScaleSetExtensionProperties.ForceUpdateTag = utils.String(v.(string)) } - future, err := client.CreateOrUpdate(ctx, resourceGroup, vmssName, name, props) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.VirtualMachineScaleSetName, id.ExtensionName, props) if err != nil { - return fmt.Errorf("creating Extension %q (Virtual Machine Scale Set %q / Resource Group %q): %+v", name, vmssName, resourceGroup, err) + return fmt.Errorf("creating %s: %+v", id, err) } if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Extension %q (Virtual Machine Scale Set %q / Resource Group %q): %+v", name, vmssName, resourceGroup, err) + return fmt.Errorf("waiting for creation of %s: %+v", id, err) } - resp, err = client.Get(ctx, resourceGroup, vmssName, name, "") - if err != nil { - return fmt.Errorf("retrieving Extension %q (Virtual Machine Scale Set %q / Resource Group %q): %+v", name, vmssName, resourceGroup, err) - } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceVirtualMachineScaleSetExtensionRead(d, meta) } diff --git a/internal/services/compute/virtual_machine_scale_set_resource.go b/internal/services/compute/virtual_machine_scale_set_resource.go index e95bd39c0927..5fe23b80cc96 100644 --- a/internal/services/compute/virtual_machine_scale_set_resource.go +++ b/internal/services/compute/virtual_machine_scale_set_resource.go @@ -794,20 +794,20 @@ func resourceVirtualMachineScaleSet() *pluginsdk.Resource { func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMScaleSetClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() log.Printf("[INFO] preparing arguments for Azure ARM Virtual Machine Scale Set creation.") - name := d.Get("name").(string) - resGroup := d.Get("resource_group_name").(string) + id := parse.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, resGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) + existing, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.ExpandTypesForGetVMScaleSetsUserData) if err != nil { if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Virtual Machine Scale Set %q (Resource Group %q): %s", name, resGroup, err) + return fmt.Errorf("checking for presence of existing %s: %s", id, err) } } @@ -903,7 +903,7 @@ func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta } properties := compute.VirtualMachineScaleSet{ - Name: &name, + Name: &id.Name, Location: &location, Tags: tags.Expand(t), Sku: sku, @@ -923,7 +923,7 @@ func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta properties.Plan = expandAzureRmVirtualMachineScaleSetPlan(d) } - future, err := client.CreateOrUpdate(ctx, resGroup, name, properties) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, properties) if err != nil { return err } @@ -932,16 +932,7 @@ func resourceVirtualMachineScaleSetCreateUpdate(d *pluginsdk.ResourceData, meta return err } - // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - read, err := client.Get(ctx, resGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) - if err != nil { - return err - } - if read.ID == nil { - return fmt.Errorf("Cannot read Virtual Machine Scale Set %s (resource group %s) ID", name, resGroup) - } - - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceVirtualMachineScaleSetRead(d, meta) } diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index 72977fa90444..4d6648ecc85a 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -348,19 +348,19 @@ func resourceWindowsVirtualMachine() *pluginsdk.Resource { func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) + id := parse.NewVirtualMachineID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - locks.ByName(name, virtualMachineResourceName) - defer locks.UnlockByName(name, virtualMachineResourceName) + locks.ByName(id.Name, virtualMachineResourceName) + defer locks.UnlockByName(id.Name, virtualMachineResourceName) - resp, err := client.Get(ctx, resourceGroup, name, compute.InstanceViewTypesUserData) + resp, err := client.Get(ctx, id.ResourceGroup, id.Name, compute.InstanceViewTypesUserData) if err != nil { if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("checking for existing Windows Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for existing Windows %s: %+v", id, err) } } @@ -389,7 +389,7 @@ func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interfa if len(errs) > 0 { return fmt.Errorf("unable to assume default computer name %s. Please adjust the %q, or specify an explicit %q", errs[0], "name", "computer_name") } - computerName = name + computerName = id.Name } enableAutomaticUpdates := d.Get("enable_automatic_updates").(bool) location := azure.NormalizeLocation(d.Get("location").(string)) @@ -425,7 +425,7 @@ func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interfa winRmListeners := expandWinRMListener(winRmListenersRaw) params := compute.VirtualMachine{ - Name: utils.String(name), + Name: utils.String(id.Name), Location: utils.String(location), Identity: identity, Plan: plan, @@ -592,25 +592,16 @@ func resourceWindowsVirtualMachineCreate(d *pluginsdk.ResourceData, meta interfa } } - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, params) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, params) if err != nil { - return fmt.Errorf("creating Windows Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating Windows %s: %+v", id, err) } if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Windows Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - read, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - return fmt.Errorf("retrieving Windows Virtual Machine %q (Resource Group %q): %+v", name, resourceGroup, err) - } - - if read.ID == nil { - return fmt.Errorf("retrieving Windows Virtual Machine %q (Resource Group %q): `id` was nil", name, resourceGroup) + return fmt.Errorf("waiting for creation of Windows %s: %+v", id, err) } - d.SetId(*read.ID) + d.SetId(id.ID()) return resourceWindowsVirtualMachineRead(d, meta) } 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 35816f73981c..01879092507c 100644 --- a/internal/services/compute/windows_virtual_machine_scale_set_resource.go +++ b/internal/services/compute/windows_virtual_machine_scale_set_resource.go @@ -316,16 +316,15 @@ func resourceWindowsVirtualMachineScaleSet() *pluginsdk.Resource { func resourceWindowsVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Compute.VMScaleSetClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - resourceGroup := d.Get("resource_group_name").(string) - name := d.Get("name").(string) - - exists, err := client.Get(ctx, resourceGroup, name, "") + id := parse.NewVirtualMachineScaleSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + exists, err := client.Get(ctx, id.ResourceGroup, id.Name, "") if err != nil { if !utils.ResponseWasNotFound(exists.Response) { - return fmt.Errorf("checking for existing Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("checking for existing Windows %s: %+v", id, err) } } @@ -414,7 +413,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 = name + computerNamePrefix = id.Name } networkProfile := &compute.VirtualMachineScaleSetNetworkProfile{ @@ -612,29 +611,19 @@ func resourceWindowsVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta props.VirtualMachineScaleSetProperties.ZoneBalance = utils.Bool(v.(bool)) } - log.Printf("[DEBUG] Creating Windows Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup) - future, err := client.CreateOrUpdate(ctx, resourceGroup, name, props) + log.Printf("[DEBUG] Creating Windows %s.", id) + future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, props) if err != nil { - return fmt.Errorf("creating Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("creating Windows %s: %+v", id, err) } - log.Printf("[DEBUG] Waiting for Windows Virtual Machine Scale Set %q (Resource Group %q) to be created..", name, resourceGroup) + log.Printf("[DEBUG] Waiting for Windows %s to be created.", id) if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) - } - log.Printf("[DEBUG] Virtual Machine Scale Set %q (Resource Group %q) was created", name, resourceGroup) - - log.Printf("[DEBUG] Retrieving Virtual Machine Scale Set %q (Resource Group %q)..", name, resourceGroup) - // Upgrading to the 2021-07-01 exposed a new expand parameter in the GET method - resp, err := client.Get(ctx, resourceGroup, name, compute.ExpandTypesForGetVMScaleSetsUserData) - if err != nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("waiting for creation of Windows %s: %+v", id, err) } + log.Printf("[DEBUG] Windows %s was created", id) - if resp.ID == nil { - return fmt.Errorf("retrieving Windows Virtual Machine Scale Set %q (Resource Group %q): ID was nil", name, resourceGroup) - } - d.SetId(*resp.ID) + d.SetId(id.ID()) return resourceWindowsVirtualMachineScaleSetRead(d, meta) }