Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependencies: updating to v0.20230808.1103829 of github.com/hashicorp/go-azure-sdk #22860

Merged
merged 9 commits into from
Aug 9, 2023
Merged
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/hashicorp/go-azure-helpers v0.58.0
github.com/hashicorp/go-azure-sdk v0.20230807.1085124
github.com/hashicorp/go-azure-sdk v0.20230808.1103829
github.com/hashicorp/go-hclog v1.4.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg=
github.com/hashicorp/go-azure-helpers v0.58.0 h1:P7KMqfBMr872m0PAyyn92IrCoEShOvkMwBVv2fMT4Ms=
github.com/hashicorp/go-azure-helpers v0.58.0/go.mod h1:BQUQp5udwbJ8pnzl0wByCLVEEyPMAFpJ9vOREiCzObo=
github.com/hashicorp/go-azure-sdk v0.20230807.1085124 h1:Mb4To2AyMGLn9UnQOdgLW3e1ai9RpOuVt9y1PAa9Xok=
github.com/hashicorp/go-azure-sdk v0.20230807.1085124/go.mod h1:3GK3YHV1vwn/jHHeUyAPWkUyYy91PEzXg0dziKlSMaA=
github.com/hashicorp/go-azure-sdk v0.20230808.1103829 h1:CngffxTjobaDVkM+Hd/rup8F+dm3E3gMfD8BXiuM+dQ=
github.com/hashicorp/go-azure-sdk v0.20230808.1103829/go.mod h1:3GK3YHV1vwn/jHHeUyAPWkUyYy91PEzXg0dziKlSMaA=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
164 changes: 110 additions & 54 deletions internal/services/compute/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
)

type Client struct {
// TODO: move the Compute client to using Meta Clients where possible
// TODO: @tombuildsstuff: investigate _if_ that's possible given Compute uses a myriad of API Versions
AvailabilitySetsClient *availabilitysets.AvailabilitySetsClient
CapacityReservationsClient *capacityreservations.CapacityReservationsClient
CapacityReservationGroupsClient *capacityreservationgroups.CapacityReservationGroupsClient
Expand Down Expand Up @@ -62,74 +64,128 @@ type Client struct {
}

func NewClient(o *common.ClientOptions) (*Client, error) {
availabilitySetsClient := availabilitysets.NewAvailabilitySetsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&availabilitySetsClient.Client, o.ResourceManagerAuthorizer)
availabilitySetsClient, err := availabilitysets.NewAvailabilitySetsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building AvailabilitySets client: %+v", err)
}
o.Configure(availabilitySetsClient.Client, o.Authorizers.ResourceManager)

capacityReservationsClient := capacityreservations.NewCapacityReservationsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&capacityReservationsClient.Client, o.ResourceManagerAuthorizer)
capacityReservationsClient, err := capacityreservations.NewCapacityReservationsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building CapacityReservations client: %+v", err)
}
o.Configure(capacityReservationsClient.Client, o.Authorizers.ResourceManager)

capacityReservationGroupsClient := capacityreservationgroups.NewCapacityReservationGroupsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&capacityReservationGroupsClient.Client, o.ResourceManagerAuthorizer)
capacityReservationGroupsClient, err := capacityreservationgroups.NewCapacityReservationGroupsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building CapacityReservationGroups client: %+v", err)
}
o.Configure(capacityReservationGroupsClient.Client, o.Authorizers.ResourceManager)

dedicatedHostsClient := dedicatedhosts.NewDedicatedHostsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&dedicatedHostsClient.Client, o.ResourceManagerAuthorizer)
dedicatedHostsClient, err := dedicatedhosts.NewDedicatedHostsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DedicatedHosts client: %+v", err)
}
o.Configure(dedicatedHostsClient.Client, o.Authorizers.ResourceManager)

dedicatedHostGroupsClient := dedicatedhostgroups.NewDedicatedHostGroupsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&dedicatedHostGroupsClient.Client, o.ResourceManagerAuthorizer)
dedicatedHostGroupsClient, err := dedicatedhostgroups.NewDedicatedHostGroupsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DedicatedHostGroups client: %+v", err)
}
o.Configure(dedicatedHostGroupsClient.Client, o.Authorizers.ResourceManager)

disksClient := disks.NewDisksClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&disksClient.Client, o.ResourceManagerAuthorizer)
disksClient, err := disks.NewDisksClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Disks client: %+v", err)
}
o.Configure(disksClient.Client, o.Authorizers.ResourceManager)

diskAccessClient := diskaccesses.NewDiskAccessesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&diskAccessClient.Client, o.ResourceManagerAuthorizer)
diskAccessClient, err := diskaccesses.NewDiskAccessesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DiskAccesses client: %+v", err)
}
o.Configure(diskAccessClient.Client, o.Authorizers.ResourceManager)

diskEncryptionSetsClient := diskencryptionsets.NewDiskEncryptionSetsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&diskEncryptionSetsClient.Client, o.ResourceManagerAuthorizer)
diskEncryptionSetsClient, err := diskencryptionsets.NewDiskEncryptionSetsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DiskEncryptionSets client: %+v", err)
}
o.Configure(diskEncryptionSetsClient.Client, o.Authorizers.ResourceManager)

galleriesClient := galleries.NewGalleriesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&galleriesClient.Client, o.ResourceManagerAuthorizer)
galleriesClient, err := galleries.NewGalleriesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Galleries client: %+v", err)
}
o.Configure(galleriesClient.Client, o.Authorizers.ResourceManager)

galleryApplicationsClient := galleryapplications.NewGalleryApplicationsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&galleryApplicationsClient.Client, o.ResourceManagerAuthorizer)
galleryApplicationsClient, err := galleryapplications.NewGalleryApplicationsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building GalleryApplications client: %+v", err)
}
o.Configure(galleryApplicationsClient.Client, o.Authorizers.ResourceManager)

galleryApplicationVersionsClient := galleryapplicationversions.NewGalleryApplicationVersionsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&galleryApplicationVersionsClient.Client, o.ResourceManagerAuthorizer)
galleryApplicationVersionsClient, err := galleryapplicationversions.NewGalleryApplicationVersionsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building GalleryApplicationVersions client: %+v", err)
}
o.Configure(galleryApplicationVersionsClient.Client, o.Authorizers.ResourceManager)

galleryImagesClient := compute.NewGalleryImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&galleryImagesClient.Client, o.ResourceManagerAuthorizer)

galleryImageVersionsClient := compute.NewGalleryImageVersionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&galleryImageVersionsClient.Client, o.ResourceManagerAuthorizer)

gallerySharingUpdateClient := gallerysharingupdate.NewGallerySharingUpdateClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&gallerySharingUpdateClient.Client, o.ResourceManagerAuthorizer)
gallerySharingUpdateClient, err := gallerysharingupdate.NewGallerySharingUpdateClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building GallerySharingUpdate client: %+v", err)
}
o.Configure(gallerySharingUpdateClient.Client, o.Authorizers.ResourceManager)

imagesClient := images.NewImagesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&imagesClient.Client, o.ResourceManagerAuthorizer)
imagesClient, err := images.NewImagesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Images client: %+v", err)
}
o.Configure(imagesClient.Client, o.Authorizers.ResourceManager)

marketplaceAgreementsClient, err := agreements.NewAgreementsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building MarketplaceAgreementsClient client: %+v", err)
}
o.Configure(marketplaceAgreementsClient.Client, o.Authorizers.ResourceManager)

proximityPlacementGroupsClient := proximityplacementgroups.NewProximityPlacementGroupsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&proximityPlacementGroupsClient.Client, o.ResourceManagerAuthorizer)
proximityPlacementGroupsClient, err := proximityplacementgroups.NewProximityPlacementGroupsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building ProximityPlacementGroups client: %+v", err)
}
o.Configure(proximityPlacementGroupsClient.Client, o.Authorizers.ResourceManager)

skusClient := skus.NewSkusClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&skusClient.Client, o.ResourceManagerAuthorizer)
skusClient, err := skus.NewSkusClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Skus client: %+v", err)
}
o.Configure(skusClient.Client, o.Authorizers.ResourceManager)

snapshotsClient := snapshots.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&snapshotsClient.Client, o.ResourceManagerAuthorizer)
snapshotsClient, err := snapshots.NewSnapshotsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Snapshots client: %+v", err)
}
o.Configure(snapshotsClient.Client, o.Authorizers.ResourceManager)

sshPublicKeysClient := sshpublickeys.NewSshPublicKeysClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&sshPublicKeysClient.Client, o.ResourceManagerAuthorizer)
sshPublicKeysClient, err := sshpublickeys.NewSshPublicKeysClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building SshPublicKeys client: %+v", err)
}
o.Configure(sshPublicKeysClient.Client, o.Authorizers.ResourceManager)

usageClient := compute.NewUsageClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&usageClient.Client, o.ResourceManagerAuthorizer)

virtualMachinesClient := virtualmachines.NewVirtualMachinesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&virtualMachinesClient.Client, o.ResourceManagerAuthorizer)
virtualMachinesClient, err := virtualmachines.NewVirtualMachinesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building VirtualMachines client: %+v", err)
}
o.Configure(virtualMachinesClient.Client, o.Authorizers.ResourceManager)

vmExtensionImageClient := compute.NewVirtualMachineExtensionImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vmExtensionImageClient.Client, o.ResourceManagerAuthorizer)
Expand All @@ -156,27 +212,27 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
o.ConfigureClient(&vmClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AvailabilitySetsClient: &availabilitySetsClient,
CapacityReservationsClient: &capacityReservationsClient,
CapacityReservationGroupsClient: &capacityReservationGroupsClient,
DedicatedHostsClient: &dedicatedHostsClient,
DedicatedHostGroupsClient: &dedicatedHostGroupsClient,
DisksClient: &disksClient,
DiskAccessClient: &diskAccessClient,
DiskEncryptionSetsClient: &diskEncryptionSetsClient,
GalleriesClient: &galleriesClient,
GalleryApplicationsClient: &galleryApplicationsClient,
GalleryApplicationVersionsClient: &galleryApplicationVersionsClient,
AvailabilitySetsClient: availabilitySetsClient,
CapacityReservationsClient: capacityReservationsClient,
CapacityReservationGroupsClient: capacityReservationGroupsClient,
DedicatedHostsClient: dedicatedHostsClient,
DedicatedHostGroupsClient: dedicatedHostGroupsClient,
DisksClient: disksClient,
DiskAccessClient: diskAccessClient,
DiskEncryptionSetsClient: diskEncryptionSetsClient,
GalleriesClient: galleriesClient,
GalleryApplicationsClient: galleryApplicationsClient,
GalleryApplicationVersionsClient: galleryApplicationVersionsClient,
GalleryImagesClient: &galleryImagesClient,
GalleryImageVersionsClient: &galleryImageVersionsClient,
GallerySharingUpdateClient: &gallerySharingUpdateClient,
ImagesClient: &imagesClient,
GallerySharingUpdateClient: gallerySharingUpdateClient,
ImagesClient: imagesClient,
MarketplaceAgreementsClient: marketplaceAgreementsClient,
ProximityPlacementGroupsClient: &proximityPlacementGroupsClient,
SkusClient: &skusClient,
SSHPublicKeysClient: &sshPublicKeysClient,
SnapshotsClient: &snapshotsClient,
VirtualMachinesClient: &virtualMachinesClient,
ProximityPlacementGroupsClient: proximityPlacementGroupsClient,
SkusClient: skusClient,
SSHPublicKeysClient: sshPublicKeysClient,
SnapshotsClient: snapshotsClient,
VirtualMachinesClient: virtualMachinesClient,
VMExtensionImageClient: &vmExtensionImageClient,
VMExtensionClient: &vmExtensionClient,
VMScaleSetClient: &vmScaleSetClient,
Expand Down
70 changes: 33 additions & 37 deletions internal/services/compute/disk_sas_token_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package compute

import (
"bytes"
"encoding/json"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -105,42 +103,40 @@ func resourceManagedDiskSasTokenCreate(d *pluginsdk.ResourceData, meta interface
return fmt.Errorf("error retrieving Disk %s: %+v", *diskId, err)
}

if model := resp.Model; model != nil {
if props := model.Properties; props != nil {
// checking whether disk export SAS URL is active already before creating. If yes, we raise an error
if string(*props.DiskState) == "ActiveSAS" {
return fmt.Errorf("active SAS Token for Disk Export already exists, cannot create another one %s: %+v", *diskId, err)
}

future, err := client.GrantAccess(ctx, *diskId, grantAccessData)
if err != nil {
return fmt.Errorf("granting access to %s: %+v", *diskId, err)
}

if err := future.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("waiting for access to be granted to %s: %+v", *diskId, err)
}

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(future.Poller.HttpResponse.Body)
if err != nil {
return err
}

var result Result
err = json.Unmarshal(buf.Bytes(), &result)
if err != nil {
return fmt.Errorf("retrieving SAS Token for Disk Access %s: %+v", *diskId, err)
}
if result.Properties.Output.AccessSAS == "" {
return fmt.Errorf("retrieving SAS Token for Disk Access %s: SAS was nil", *diskId)
}

d.SetId(diskId.ID())
sasToken := result.Properties.Output.AccessSAS
d.Set("sas_url", sasToken)
}
if resp.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", *diskId)
}
if resp.Model.Properties == nil {
return fmt.Errorf("retrieving %s: `model.Properties` was nil", *diskId)
}
props := *resp.Model.Properties

// checking whether disk export SAS URL is active already before creating. If yes, we raise an error
if *props.DiskState == disks.DiskStateActiveSAS {
return fmt.Errorf("active SAS Token for Disk Export already exists, cannot create another one %s: %+v", *diskId, err)
}

future, err := client.GrantAccess(ctx, *diskId, grantAccessData)
if err != nil {
return fmt.Errorf("granting access to %s: %+v", *diskId, err)
}
if err := future.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("waiting for access to be granted to %s: %+v", *diskId, err)
}

lastResponse := future.Poller.LatestResponse()
if lastResponse == nil {
return fmt.Errorf("waiting for access to be granted to %s: last response was nil", *diskId)
}

var result Result
if err := lastResponse.Unmarshal(&result); err != nil {
return fmt.Errorf("retrieving SAS Token for Disk Access %s: %+v", *diskId, err)
}

d.SetId(diskId.ID())
sasToken := result.Properties.Output.AccessSAS
d.Set("sas_url", sasToken)

return resourceManagedDiskSasTokenRead(d, meta)
}
Expand Down
12 changes: 12 additions & 0 deletions internal/services/compute/image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
Expand Down Expand Up @@ -209,6 +210,12 @@ func (ImageResource) generalizeVirtualMachine(data acceptance.TestData) func(con
return err
}

if _, ok := ctx.Deadline(); !ok {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, 15*time.Minute)
defer cancel()
}

// these are nested in a Set in the Legacy VM resource, simpler to compute them
userName := fmt.Sprintf("testadmin%d", data.RandomInteger)
password := fmt.Sprintf("Password1234!%d", data.RandomInteger)
Expand Down Expand Up @@ -307,6 +314,11 @@ func (ImageResource) virtualMachineExists(ctx context.Context, client *clients.C
return err
}

if _, ok := ctx.Deadline(); !ok {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, 15*time.Minute)
defer cancel()
}
resp, err := client.Compute.VirtualMachinesClient.Get(ctx, *id, virtualmachines.DefaultGetOperationOptions())
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
Expand Down
13 changes: 2 additions & 11 deletions internal/services/compute/linux_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"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/2021-11-01/availabilitysets"
Expand Down Expand Up @@ -1655,16 +1654,8 @@ func resourceLinuxVirtualMachineDelete(d *pluginsdk.ResourceData, meta interface
return err
}

diskDeleteFuture, err := disksClient.Delete(ctx, *diskId)
if err != nil {
if !response.WasNotFound(diskDeleteFuture.HttpResponse) {
return fmt.Errorf("deleting OS Disk %q (Resource Group %q) for Linux Virtual Machine %q (Resource Group %q): %+v", diskId.DiskName, diskId.ResourceGroupName, id.Name, id.ResourceGroup, err)
}
}
if !response.WasNotFound(diskDeleteFuture.HttpResponse) {
if err := diskDeleteFuture.Poller.PollUntilDone(); err != nil {
return fmt.Errorf("OS Disk %q (Resource Group %q) for Linux Virtual Machine %q (Resource Group %q): %+v", diskId.DiskName, diskId.ResourceGroupName, id.Name, id.ResourceGroup, err)
}
if err := disksClient.DeleteThenPoll(ctx, *diskId); err != nil {
return fmt.Errorf("deleting OS Disk %q (Resource Group %q) for Linux Virtual Machine %q (Resource Group %q): %+v", diskId.DiskName, diskId.ResourceGroupName, id.Name, id.ResourceGroup, err)
}

log.Printf("[DEBUG] Deleted OS Disk from Linux Virtual Machine %q (Resource Group %q).", diskId.DiskName, diskId.ResourceGroupName)
Expand Down
Loading