From 9b3ef24c6e59be6845af9198e14338f7d6b883a6 Mon Sep 17 00:00:00 2001 From: Yichun Ma Date: Wed, 26 Oct 2022 13:19:23 +0800 Subject: [PATCH] `azurerm_managed_disk` - remove old parse/validate --- .../compute/disk_sas_token_resource.go | 6 +- .../services/compute/managed_disk_resource.go | 2 +- .../services/compute/parse/managed_disk.go | 69 ----------- .../compute/parse/managed_disk_test.go | 112 ------------------ internal/services/compute/resourceids.go | 1 - .../compute/validate/managed_disk_id.go | 23 ---- .../compute/validate/managed_disk_id_test.go | 76 ------------ ...rotection_backup_instance_disk_resource.go | 7 +- .../disk_pool_iscsi_target_lun_resource.go | 4 +- ...k_pool_managed_disk_attachment_resource.go | 19 ++- .../disk_pool_managed_disk_attachment.go | 8 +- .../disk_pool_managed_disk_attachment_test.go | 4 +- .../services/disks/parse/iscsitarget_lun.go | 8 +- .../disks/parse/iscsitarget_lun_test.go | 8 +- .../legacy/virtual_machine_resource.go | 15 +-- .../legacy/virtual_machine_resource_test.go | 11 +- 16 files changed, 45 insertions(+), 328 deletions(-) delete mode 100644 internal/services/compute/parse/managed_disk.go delete mode 100644 internal/services/compute/parse/managed_disk_test.go delete mode 100644 internal/services/compute/validate/managed_disk_id.go delete mode 100644 internal/services/compute/validate/managed_disk_id_test.go diff --git a/internal/services/compute/disk_sas_token_resource.go b/internal/services/compute/disk_sas_token_resource.go index ba59c398e961..5664769a740b 100644 --- a/internal/services/compute/disk_sas_token_resource.go +++ b/internal/services/compute/disk_sas_token_resource.go @@ -9,8 +9,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "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" @@ -42,7 +40,7 @@ func resourceManagedDiskSasToken() *pluginsdk.Resource { }, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.ManagedDiskID(id) + _, err := disks.ParseDiskID(id) return err }), @@ -51,7 +49,7 @@ func resourceManagedDiskSasToken() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate.ManagedDiskID, + ValidateFunc: disks.ValidateDiskID, }, // unable to provide upper value of 4294967295 as it's not comptabile with 32-bit (overflow errors) diff --git a/internal/services/compute/managed_disk_resource.go b/internal/services/compute/managed_disk_resource.go index 13e30a28660e..79a597215def 100644 --- a/internal/services/compute/managed_disk_resource.go +++ b/internal/services/compute/managed_disk_resource.go @@ -41,7 +41,7 @@ func resourceManagedDisk() *pluginsdk.Resource { }), Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.ManagedDiskID(id) + _, err := disks.ParseDiskID(id) return err }), diff --git a/internal/services/compute/parse/managed_disk.go b/internal/services/compute/parse/managed_disk.go deleted file mode 100644 index 006142550e96..000000000000 --- a/internal/services/compute/parse/managed_disk.go +++ /dev/null @@ -1,69 +0,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 ManagedDiskId struct { - SubscriptionId string - ResourceGroup string - DiskName string -} - -func NewManagedDiskID(subscriptionId, resourceGroup, diskName string) ManagedDiskId { - return ManagedDiskId{ - SubscriptionId: subscriptionId, - ResourceGroup: resourceGroup, - DiskName: diskName, - } -} - -func (id ManagedDiskId) String() string { - segments := []string{ - fmt.Sprintf("Disk Name %q", id.DiskName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Managed Disk", segmentsStr) -} - -func (id ManagedDiskId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/disks/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.DiskName) -} - -// ManagedDiskID parses a ManagedDisk ID into an ManagedDiskId struct -func ManagedDiskID(input string) (*ManagedDiskId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, err - } - - resourceId := ManagedDiskId{ - 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.DiskName, err = id.PopSegment("disks"); 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/managed_disk_test.go b/internal/services/compute/parse/managed_disk_test.go deleted file mode 100644 index 76c228d7a178..000000000000 --- a/internal/services/compute/parse/managed_disk_test.go +++ /dev/null @@ -1,112 +0,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 = ManagedDiskId{} - -func TestManagedDiskIDFormatter(t *testing.T) { - actual := NewManagedDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/disk1" - if actual != expected { - t.Fatalf("Expected %q but got %q", expected, actual) - } -} - -func TestManagedDiskID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ManagedDiskId - }{ - - { - // 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 DiskName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/", - Error: true, - }, - - { - // missing value for DiskName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/", - Error: true, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/disk1", - Expected: &ManagedDiskId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroup: "resGroup1", - DiskName: "disk1", - }, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.COMPUTE/DISKS/DISK1", - Error: true, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ManagedDiskID(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.DiskName != v.Expected.DiskName { - t.Fatalf("Expected %q but got %q for DiskName", v.Expected.DiskName, actual.DiskName) - } - } -} diff --git a/internal/services/compute/resourceids.go b/internal/services/compute/resourceids.go index 1ef1ea274ea7..3f670c5ec042 100644 --- a/internal/services/compute/resourceids.go +++ b/internal/services/compute/resourceids.go @@ -6,7 +6,6 @@ package compute //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=GalleryApplication -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/galleries/gallery1/applications/galleryApplication1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=GalleryApplicationVersion -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/galleries/gallery1/applications/galleryApplication1/versions/galleryApplicationVersion1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Image -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/images/image1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ManagedDisk -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/disk1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SharedImage -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/galleries/gallery1/images/image1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SharedImageGallery -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/galleries/gallery1 //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 diff --git a/internal/services/compute/validate/managed_disk_id.go b/internal/services/compute/validate/managed_disk_id.go deleted file mode 100644 index cb559b9e8e56..000000000000 --- a/internal/services/compute/validate/managed_disk_id.go +++ /dev/null @@ -1,23 +0,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 ManagedDiskID(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.ManagedDiskID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/compute/validate/managed_disk_id_test.go b/internal/services/compute/validate/managed_disk_id_test.go deleted file mode 100644 index d78f640062d9..000000000000 --- a/internal/services/compute/validate/managed_disk_id_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestManagedDiskID(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 DiskName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/", - Valid: false, - }, - - { - // missing value for DiskName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/disk1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.COMPUTE/DISKS/DISK1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := ManagedDiskID(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/dataprotection/data_protection_backup_instance_disk_resource.go b/internal/services/dataprotection/data_protection_backup_instance_disk_resource.go index 9afba5a836c5..467f3dcee1b7 100644 --- a/internal/services/dataprotection/data_protection_backup_instance_disk_resource.go +++ b/internal/services/dataprotection/data_protection_backup_instance_disk_resource.go @@ -8,13 +8,12 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "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/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2022-04-01/backupinstances" "github.com/hashicorp/go-azure-sdk/resource-manager/dataprotection/2022-04-01/backuppolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "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" resourceParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" azSchema "github.com/hashicorp/terraform-provider-azurerm/internal/tf/schema" @@ -61,7 +60,7 @@ func resourceDataProtectionBackupInstanceDisk() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: computeValidate.ManagedDiskID, + ValidateFunc: disks.ValidateDiskID, }, "snapshot_resource_group_name": commonschema.ResourceGroupName(), @@ -97,7 +96,7 @@ func resourceDataProtectionBackupInstanceDiskCreateUpdate(d *schema.ResourceData } } - diskId, _ := computeParse.ManagedDiskID(d.Get("disk_id").(string)) + diskId, _ := disks.ParseDiskID(d.Get("disk_id").(string)) location := location.Normalize(d.Get("location").(string)) policyId, _ := backuppolicies.ParseBackupPolicyID(d.Get("backup_policy_id").(string)) snapshotResourceGroupId := resourceParse.NewResourceGroupID(subscriptionId, d.Get("snapshot_resource_group_name").(string)) diff --git a/internal/services/disks/disk_pool_iscsi_target_lun_resource.go b/internal/services/disks/disk_pool_iscsi_target_lun_resource.go index 1ea6d616b5f3..621ac3480941 100644 --- a/internal/services/disks/disk_pool_iscsi_target_lun_resource.go +++ b/internal/services/disks/disk_pool_iscsi_target_lun_resource.go @@ -9,13 +9,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/diskpools" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/iscsitargets" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" - computeParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/disks/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/disks/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -176,7 +176,7 @@ func (d DiskPoolIscsiTargetLunModel) Read() sdk.ResourceFunc { for _, lun := range *resp.Model.Properties.Luns { if lun.ManagedDiskAzureResourceId == id.ManagedDiskId.ID() { diskPoolId := diskpools.NewDiskPoolID(iscsiTargetId.SubscriptionId, iscsiTargetId.ResourceGroupName, iscsiTargetId.DiskPoolName) - diskId, err := computeParse.ManagedDiskID(lun.ManagedDiskAzureResourceId) + diskId, err := disks.ParseDiskID(lun.ManagedDiskAzureResourceId) if err != nil { return fmt.Errorf("invalid managed disk id in iscsi target response %q : %q", iscsiTargetId.ID(), lun.ManagedDiskAzureResourceId) } diff --git a/internal/services/disks/disk_pool_managed_disk_attachment_resource.go b/internal/services/disks/disk_pool_managed_disk_attachment_resource.go index d2722bf05525..8b409e153898 100644 --- a/internal/services/disks/disk_pool_managed_disk_attachment_resource.go +++ b/internal/services/disks/disk_pool_managed_disk_attachment_resource.go @@ -6,12 +6,11 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/diskpools" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" - computeParse "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/services/disks/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/disks/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -43,7 +42,7 @@ func (d DiskPoolManagedDiskAttachmentResource) Arguments() map[string]*schema.Sc Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: computeValidate.ManagedDiskID, + ValidateFunc: disks.ValidateDiskID, }, } } @@ -77,7 +76,7 @@ func (d DiskPoolManagedDiskAttachmentResource) Create() sdk.ResourceFunc { if poolId.SubscriptionId != subscriptionId { return fmt.Errorf("Disk Pool subscription id %q is different from provider's subscription", poolId.SubscriptionId) } - diskId, err := computeParse.ManagedDiskID(attachment.DiskId) + diskId, err := disks.ParseDiskID(attachment.DiskId) if err != nil { return err } @@ -91,12 +90,12 @@ func (d DiskPoolManagedDiskAttachmentResource) Create() sdk.ResourceFunc { return fmt.Errorf("retrieving %q: %+v", *poolId, err) } - disks := make([]diskpools.Disk, 0) + inputDisks := make([]diskpools.Disk, 0) if poolResp.Model != nil && poolResp.Model.Properties.Disks != nil { - disks = *poolResp.Model.Properties.Disks + inputDisks = *poolResp.Model.Properties.Disks } - for _, disk := range disks { - existedDiskId, err := computeParse.ManagedDiskID(disk.Id) + for _, disk := range inputDisks { + existedDiskId, err := disks.ParseDiskID(disk.Id) if err != nil { return fmt.Errorf("error on parsing existing attached disk id %q %+v", disk.Id, err) } @@ -105,13 +104,13 @@ func (d DiskPoolManagedDiskAttachmentResource) Create() sdk.ResourceFunc { } } - disks = append(disks, diskpools.Disk{ + inputDisks = append(inputDisks, diskpools.Disk{ Id: diskId.ID(), }) err = client.UpdateThenPoll(ctx, *poolId, diskpools.DiskPoolUpdate{ Properties: diskpools.DiskPoolUpdateProperties{ - Disks: &disks, + Disks: &inputDisks, }, }) if err != nil { diff --git a/internal/services/disks/parse/disk_pool_managed_disk_attachment.go b/internal/services/disks/parse/disk_pool_managed_disk_attachment.go index 1a730503ff9b..5b89e103d8ac 100644 --- a/internal/services/disks/parse/disk_pool_managed_disk_attachment.go +++ b/internal/services/disks/parse/disk_pool_managed_disk_attachment.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/diskpools" - computeParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" ) const storageDiskPoolManagedDiskAttachmentIdSeparator = "/managedDisks|" @@ -15,10 +15,10 @@ var _ resourceids.Id = DiskPoolManagedDiskAttachmentId{} type DiskPoolManagedDiskAttachmentId struct { DiskPoolId diskpools.DiskPoolId - ManagedDiskId computeParse.ManagedDiskId + ManagedDiskId disks.DiskId } -func NewDiskPoolManagedDiskAttachmentId(diskPoolId diskpools.DiskPoolId, managedDiskId computeParse.ManagedDiskId) DiskPoolManagedDiskAttachmentId { +func NewDiskPoolManagedDiskAttachmentId(diskPoolId diskpools.DiskPoolId, managedDiskId disks.DiskId) DiskPoolManagedDiskAttachmentId { return DiskPoolManagedDiskAttachmentId{ DiskPoolId: diskPoolId, ManagedDiskId: managedDiskId, @@ -53,7 +53,7 @@ func DiskPoolManagedDiskAttachmentID(input string) (*DiskPoolManagedDiskAttachme if err != nil { return nil, fmt.Errorf("malformed disks pool id: %q, %v", poolId.ID(), err) } - diskId, err := computeParse.ManagedDiskID(parts[1]) + diskId, err := disks.ParseDiskID(parts[1]) if diskId == nil { return nil, fmt.Errorf("malformed disks pool managed disk attachment id:%q", input) } diff --git a/internal/services/disks/parse/disk_pool_managed_disk_attachment_test.go b/internal/services/disks/parse/disk_pool_managed_disk_attachment_test.go index 77c721463dd3..5581088fc2af 100644 --- a/internal/services/disks/parse/disk_pool_managed_disk_attachment_test.go +++ b/internal/services/disks/parse/disk_pool_managed_disk_attachment_test.go @@ -3,13 +3,13 @@ package parse import ( "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/diskpools" - computeparse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" ) func TestDiskPoolManagedDiskAttachmentIDFormatter(t *testing.T) { diskPoolId := diskpools.NewDiskPoolID("12345678-1234-9876-4563-123456789012", "resGroup1", "storagePool1") - managedDiskId := computeparse.NewManagedDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "diks1") + managedDiskId := disks.NewDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "diks1") actual := NewDiskPoolManagedDiskAttachmentId(diskPoolId, managedDiskId).ID() expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.StoragePool/diskPools/storagePool1/managedDisks|/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/diks1" if actual != expected { diff --git a/internal/services/disks/parse/iscsitarget_lun.go b/internal/services/disks/parse/iscsitarget_lun.go index 03a1789773d6..4037337e3a0b 100644 --- a/internal/services/disks/parse/iscsitarget_lun.go +++ b/internal/services/disks/parse/iscsitarget_lun.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/iscsitargets" - computeParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" ) const iscsiTargetLunSeparator = "/lun|" @@ -15,10 +15,10 @@ var _ resourceids.Id = DiskPoolIscsiTargetLunId{} type DiskPoolIscsiTargetLunId struct { IscsiTargetId iscsitargets.IscsiTargetId - ManagedDiskId computeParse.ManagedDiskId + ManagedDiskId disks.DiskId } -func NewDiskPoolIscsiTargetLunId(iscsiTargetId iscsitargets.IscsiTargetId, managedDiskId computeParse.ManagedDiskId) DiskPoolIscsiTargetLunId { +func NewDiskPoolIscsiTargetLunId(iscsiTargetId iscsitargets.IscsiTargetId, managedDiskId disks.DiskId) DiskPoolIscsiTargetLunId { return DiskPoolIscsiTargetLunId{ IscsiTargetId: iscsiTargetId, ManagedDiskId: managedDiskId, @@ -53,7 +53,7 @@ func IscsiTargetLunID(input string) (*DiskPoolIscsiTargetLunId, error) { if err != nil { return nil, fmt.Errorf("malformed iscsi target id: %q, %v", input, err) } - managedDiskId, err := computeParse.ManagedDiskID(parts[1]) + managedDiskId, err := disks.ParseDiskID(parts[1]) if managedDiskId == nil { return nil, fmt.Errorf("malformed iscsi target id: %q", input) } diff --git a/internal/services/disks/parse/iscsitarget_lun_test.go b/internal/services/disks/parse/iscsitarget_lun_test.go index ef1a8a044ddc..62fc2ac99efe 100644 --- a/internal/services/disks/parse/iscsitarget_lun_test.go +++ b/internal/services/disks/parse/iscsitarget_lun_test.go @@ -3,13 +3,13 @@ package parse import ( "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/storagepool/2021-08-01/iscsitargets" - computeParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" ) func TestNewDiskPoolIscsiTargetLunId(t *testing.T) { iscsiTargetId := iscsitargets.NewIscsiTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskPoolValue", "iscsiTargetValue") - managedDiskId := computeParse.NewManagedDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1") + managedDiskId := disks.NewDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1") id := NewDiskPoolIscsiTargetLunId(iscsiTargetId, managedDiskId) if id.IscsiTargetId != iscsiTargetId { @@ -23,7 +23,7 @@ func TestNewDiskPoolIscsiTargetLunId(t *testing.T) { func TestFormatIscsiTargetLunId(t *testing.T) { iscsiTargetId := iscsitargets.NewIscsiTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskPoolValue", "iscsiTargetValue") - managedDiskId := computeParse.NewManagedDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1") + managedDiskId := disks.NewDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1") id := NewDiskPoolIscsiTargetLunId(iscsiTargetId, managedDiskId) expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StoragePool/diskPools/diskPoolValue/iscsiTargets/iscsiTargetValue/lun|/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/disk1" @@ -104,7 +104,7 @@ func TestParseIscsiTargetLunID(t *testing.T) { Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StoragePool/diskPools/diskPoolValue/iscsiTargets/iscsiTargetValue/lun|/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Compute/disks/disk1", Expected: &DiskPoolIscsiTargetLunId{ IscsiTargetId: iscsitargets.NewIscsiTargetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskPoolValue", "iscsiTargetValue"), - ManagedDiskId: computeParse.NewManagedDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1"), + ManagedDiskId: disks.NewDiskID("12345678-1234-9876-4563-123456789012", "resGroup1", "disk1"), }, }, { diff --git a/internal/services/legacy/virtual_machine_resource.go b/internal/services/legacy/virtual_machine_resource.go index 0c66917c1785..42d36417550a 100644 --- a/internal/services/legacy/virtual_machine_resource.go +++ b/internal/services/legacy/virtual_machine_resource.go @@ -13,6 +13,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -1074,18 +1075,18 @@ func resourceVirtualMachineDeleteManagedDisk(d *pluginsdk.ResourceData, disk *co ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.ManagedDiskID(managedDiskID) + id, err := disks.ParseDiskID(managedDiskID) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.DiskName) + future, err := client.Delete(ctx, id.ResourceGroupName, id.DiskName) if err != nil { - return fmt.Errorf("deleting Managed Disk %q (Resource Group %q) %+v", id.DiskName, id.ResourceGroup, err) + return fmt.Errorf("deleting Managed Disk %s: %+v", *id, err) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of Managed Disk %q (Resource Group %q) %+v", id.DiskName, id.ResourceGroup, err) + return fmt.Errorf("waiting for deletion of %s: %+v", *id, err) } return nil @@ -1962,14 +1963,14 @@ func resourceVirtualMachineGetManagedDiskInfo(d *pluginsdk.ResourceData, disk *c } diskId := *disk.ID - id, err := parse.ManagedDiskID(diskId) + id, err := disks.ParseDiskID(diskId) if err != nil { return nil, fmt.Errorf("parsing Disk ID %q: %+v", diskId, err) } - diskResp, err := client.Get(ctx, id.ResourceGroup, id.DiskName) + diskResp, err := client.Get(ctx, id.ResourceGroupName, id.DiskName) if err != nil { - return nil, fmt.Errorf("retrieving Disk %q : %+v", id.String(), err) + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) } return &diskResp, nil diff --git a/internal/services/legacy/virtual_machine_resource_test.go b/internal/services/legacy/virtual_machine_resource_test.go index 7c1a70356a4b..7eac4f47eeed 100644 --- a/internal/services/legacy/virtual_machine_resource_test.go +++ b/internal/services/legacy/virtual_machine_resource_test.go @@ -5,6 +5,7 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "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" @@ -112,12 +113,12 @@ func (VirtualMachineResource) Exists(ctx context.Context, clients *clients.Clien func (VirtualMachineResource) managedDiskDelete(diskId *string) acceptance.ClientCheckFunc { return func(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.ManagedDiskID(*diskId) + id, err := disks.ParseDiskID(*diskId) if err != nil { return err } - disk, err := clients.Legacy.DisksClient.Get(ctx, id.ResourceGroup, id.DiskName) + disk, err := clients.Legacy.DisksClient.Get(ctx, id.ResourceGroupName, id.DiskName) if err != nil { if utils.ResponseWasNotFound(disk.Response) { return fmt.Errorf("disk %s does not exist", *id) @@ -125,7 +126,7 @@ func (VirtualMachineResource) managedDiskDelete(diskId *string) acceptance.Clien return err } - future, err := clients.Legacy.DisksClient.Delete(ctx, id.ResourceGroup, id.DiskName) + future, err := clients.Legacy.DisksClient.Delete(ctx, id.ResourceGroupName, id.DiskName) if err != nil { return fmt.Errorf("deleting disk %q: %s", id.String(), err) } @@ -140,12 +141,12 @@ func (VirtualMachineResource) managedDiskDelete(diskId *string) acceptance.Clien func (VirtualMachineResource) managedDiskExists(diskId *string, shouldExist bool) acceptance.ClientCheckFunc { return func(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) error { - id, err := parse.ManagedDiskID(*diskId) + id, err := disks.ParseDiskID(*diskId) if err != nil { return err } - disk, err := clients.Legacy.DisksClient.Get(ctx, id.ResourceGroup, id.DiskName) + disk, err := clients.Legacy.DisksClient.Get(ctx, id.ResourceGroupName, id.DiskName) if err != nil { if utils.ResponseWasNotFound(disk.Response) { if !shouldExist {