From 9f163ab007b62c4ade3e8838d8797cf9ef989832 Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Thu, 15 Sep 2022 12:43:49 +0800 Subject: [PATCH 1/6] `azurerm_managed_disk` - support for the `userAssignedIdentity` property --- internal/services/compute/client/client.go | 5 +- .../services/compute/disk_encryption_set.go | 23 ++- .../disk_encryption_set_data_source.go | 26 +-- .../compute/disk_encryption_set_resource.go | 164 +++++++-------- .../disk_encryption_set_resource_test.go | 145 +++++++++++++- .../compute/linux_virtual_machine_resource.go | 2 +- .../services/compute/managed_disk_resource.go | 4 +- .../windows_virtual_machine_resource.go | 2 +- .../2022-03-02/diskencryptionsets/README.md | 133 +++++++++++++ .../2022-03-02/diskencryptionsets/client.go | 18 ++ .../diskencryptionsets/constants.go | 37 ++++ .../id_diskencryptionset.go | 124 ++++++++++++ .../method_createorupdate_autorest.go | 79 ++++++++ .../method_delete_autorest.go | 78 ++++++++ .../diskencryptionsets/method_get_autorest.go | 68 +++++++ .../method_list_autorest.go | 187 ++++++++++++++++++ ...method_listassociatedresources_autorest.go | 177 +++++++++++++++++ .../method_listbyresourcegroup_autorest.go | 187 ++++++++++++++++++ .../method_update_autorest.go | 79 ++++++++ .../diskencryptionsets/model_apierror.go | 12 ++ .../diskencryptionsets/model_apierrorbase.go | 10 + .../model_diskencryptionset.go | 18 ++ .../model_diskencryptionsetupdate.go | 14 ++ ...model_diskencryptionsetupdateproperties.go | 11 ++ .../model_encryptionsetproperties.go | 33 ++++ .../diskencryptionsets/model_innererror.go | 9 + .../model_keyfordiskencryptionset.go | 9 + .../diskencryptionsets/model_sourcevault.go | 8 + .../diskencryptionsets/predicates.go | 29 +++ .../2022-03-02/diskencryptionsets/version.go | 12 ++ vendor/modules.txt | 1 + .../docs/r/disk_encryption_set.html.markdown | 6 +- 32 files changed, 1575 insertions(+), 135 deletions(-) create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/id_diskencryptionset.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_createorupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_delete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_get_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_list_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listassociatedresources_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listbyresourcegroup_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_update_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierror.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierrorbase.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionset.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdateproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_encryptionsetproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_innererror.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_keyfordiskencryptionset.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_sourcevault.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/version.go diff --git a/internal/services/compute/client/client.go b/internal/services/compute/client/client.go index d3cf4358d2d0..ecac789585fc 100644 --- a/internal/services/compute/client/client.go +++ b/internal/services/compute/client/client.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedhosts" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/proximityplacementgroups" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/sshpublickeys" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -19,7 +20,7 @@ type Client struct { DedicatedHostGroupsClient *dedicatedhostgroups.DedicatedHostGroupsClient DisksClient *compute.DisksClient DiskAccessClient *compute.DiskAccessesClient - DiskEncryptionSetsClient *compute.DiskEncryptionSetsClient + DiskEncryptionSetsClient *diskencryptionsets.DiskEncryptionSetsClient GalleriesClient *compute.GalleriesClient GalleryApplicationsClient *compute.GalleryApplicationsClient GalleryApplicationVersionsClient *compute.GalleryApplicationVersionsClient @@ -63,7 +64,7 @@ func NewClient(o *common.ClientOptions) *Client { diskAccessClient := compute.NewDiskAccessesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&diskAccessClient.Client, o.ResourceManagerAuthorizer) - diskEncryptionSetsClient := compute.NewDiskEncryptionSetsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + diskEncryptionSetsClient := diskencryptionsets.NewDiskEncryptionSetsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&diskEncryptionSetsClient.Client, o.ResourceManagerAuthorizer) galleriesClient := compute.NewGalleriesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) diff --git a/internal/services/compute/disk_encryption_set.go b/internal/services/compute/disk_encryption_set.go index c33f6f3255dd..8df6bb7eed25 100644 --- a/internal/services/compute/disk_encryption_set.go +++ b/internal/services/compute/disk_encryption_set.go @@ -4,30 +4,29 @@ import ( "context" "fmt" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" ) -// retrieveDiskEncryptionSetEncryptionType returns encryption type of the disk encryption set -func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *compute.DiskEncryptionSetsClient, diskEncryptionSetId string) (*compute.EncryptionType, error) { - diskEncryptionSet, err := parse.DiskEncryptionSetID(diskEncryptionSetId) +func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *diskencryptionsets.DiskEncryptionSetsClient, diskEncryptionSetId string) (*diskencryptionsets.DiskEncryptionSetType, error) { + id, err := diskencryptionsets.ParseDiskEncryptionSetID(diskEncryptionSetId) if err != nil { return nil, err } - resp, err := client.Get(ctx, diskEncryptionSet.ResourceGroup, diskEncryptionSet.Name) + resp, err := client.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving %s: %+v", *diskEncryptionSet, err) + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) } + var encryptionType *diskencryptionsets.DiskEncryptionSetType - var encryptionType *compute.EncryptionType - if props := resp.EncryptionSetProperties; props != nil && string(props.EncryptionType) != "" { - v := compute.EncryptionType(props.EncryptionType) - encryptionType = &v + if model := resp.Model; model != nil { + if props := model.Properties; props != nil && props.EncryptionType != nil { + encryptionType = props.EncryptionType + } } if encryptionType == nil { - return nil, fmt.Errorf("retrieving %s: EncryptionType was nil", *diskEncryptionSet) + return nil, fmt.Errorf("retrieving %s: EncryptionType was nil", *id) } return encryptionType, nil diff --git a/internal/services/compute/disk_encryption_set_data_source.go b/internal/services/compute/disk_encryption_set_data_source.go index 6533c11a0d03..7eca551f6eba 100644 --- a/internal/services/compute/disk_encryption_set_data_source.go +++ b/internal/services/compute/disk_encryption_set_data_source.go @@ -4,11 +4,12 @@ import ( "fmt" "time" + "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-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" "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" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -39,7 +40,7 @@ func dataSourceDiskEncryptionSet() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -50,11 +51,12 @@ func dataSourceDiskEncryptionSetRead(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewDiskEncryptionSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := diskencryptionsets.NewDiskEncryptionSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + resp, err := client.Get(ctx, id) + model := resp.Model + if err != nil || model == nil { + if response.WasNotFound(resp.HttpResponse) { return fmt.Errorf("%s was not found", id) } return fmt.Errorf("reading %s: %+v", id, err) @@ -62,14 +64,14 @@ func dataSourceDiskEncryptionSetRead(d *pluginsdk.ResourceData, meta interface{} d.SetId(id.ID()) - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("name", id.DiskEncryptionSetName) + d.Set("resource_group_name", id.ResourceGroupName) - d.Set("location", location.NormalizeNilable(resp.Location)) + d.Set("location", location.NormalizeNilable(utils.String(model.Location))) - if props := resp.EncryptionSetProperties; props != nil { + if props := model.Properties; props != nil { d.Set("auto_key_rotation_enabled", props.RotationToLatestKeyVersionEnabled) } - return tags.FlattenAndSet(d, resp.Tags) + return tags.FlattenAndSet(d, model.Tags) } diff --git a/internal/services/compute/disk_encryption_set_resource.go b/internal/services/compute/disk_encryption_set_resource.go index 588ce5929550..d03908b20031 100644 --- a/internal/services/compute/disk_encryption_set_resource.go +++ b/internal/services/compute/disk_encryption_set_resource.go @@ -6,9 +6,12 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -18,7 +21,6 @@ import ( keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" resourcesClient "github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/client" - "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" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -71,20 +73,17 @@ func resourceDiskEncryptionSet() *pluginsdk.Resource { Type: pluginsdk.TypeString, Optional: true, ForceNew: true, - Default: string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey), + Default: string(diskencryptionsets.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey), ValidateFunc: validation.StringInSlice([]string{ - string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey), - string(compute.DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys), - string(compute.DiskEncryptionSetTypeConfidentialVMEncryptedWithCustomerKey), + string(diskencryptionsets.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey), + string(diskencryptionsets.DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys), + string(diskencryptionsets.DiskEncryptionSetTypeConfidentialVmEncryptedWithCustomerKey), }, false), }, - // whilst the API Documentation shows optional - attempting to send nothing returns: - // `Required parameter 'ResourceIdentity' is missing (null)` - // hence this is required - "identity": commonschema.SystemAssignedIdentityRequired(), + "identity": commonschema.SystemAssignedUserAssignedIdentityRequired(), - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -97,15 +96,15 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewDiskEncryptionSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := diskencryptionsets.NewDiskEncryptionSetID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - existing, err := client.Get(ctx, id.ResourceGroup, id.Name) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for present of existing %s: %+v", id, err) } } - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return tf.ImportAsExistsError("azurerm_disk_encryption_set", id.ID()) } @@ -124,9 +123,8 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} } } - location := azure.NormalizeLocation(d.Get("location").(string)) rotationToLatestKeyVersionEnabled := d.Get("auto_key_rotation_enabled").(bool) - encryptionType := d.Get("encryption_type").(string) + encryptionType := diskencryptionsets.DiskEncryptionSetType(d.Get("encryption_type").(string)) t := d.Get("tags").(map[string]interface{}) expandedIdentity, err := expandDiskEncryptionSetIdentity(d.Get("identity").([]interface{})) @@ -134,32 +132,26 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} return fmt.Errorf("expanding `identity`: %+v", err) } - params := compute.DiskEncryptionSet{ - Location: utils.String(location), - EncryptionSetProperties: &compute.EncryptionSetProperties{ - ActiveKey: &compute.KeyForDiskEncryptionSet{ - KeyURL: utils.String(keyVaultKeyId), + params := diskencryptionsets.DiskEncryptionSet{ + Location: location.Normalize(d.Get("location").(string)), + Properties: &diskencryptionsets.EncryptionSetProperties{ + ActiveKey: &diskencryptionsets.KeyForDiskEncryptionSet{ + KeyUrl: keyVaultKeyId, + SourceVault: &diskencryptionsets.SourceVault{ + Id: utils.String(keyVaultDetails.keyVaultId), + }, }, RotationToLatestKeyVersionEnabled: utils.Bool(rotationToLatestKeyVersionEnabled), - EncryptionType: compute.DiskEncryptionSetType(encryptionType), + EncryptionType: &encryptionType, }, Identity: expandedIdentity, Tags: tags.Expand(t), } - if keyVaultDetails != nil { - params.EncryptionSetProperties.ActiveKey.SourceVault = &compute.SourceVault{ - ID: utils.String(keyVaultDetails.keyVaultId), - } - } - - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, params) + err = client.CreateOrUpdateThenPoll(ctx, id, params) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of %s: %+v", id, err) - } d.SetId(id.ID()) @@ -171,47 +163,58 @@ func resourceDiskEncryptionSetRead(d *pluginsdk.ResourceData, meta interface{}) ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.DiskEncryptionSetID(d.Id()) + id, err := diskencryptionsets.ParseDiskEncryptionSetID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[INFO] Disk Encryption Set %q does not exist - removing from state", d.Id()) d.SetId("") return nil } - return fmt.Errorf("reading Disk Encryption Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("reading Disk Encryption Set %q (Resource Group %q): %+v", id.DiskEncryptionSetName, id.ResourceGroupName, err) + } + + d.Set("name", id.DiskEncryptionSetName) + d.Set("resource_group_name", id.ResourceGroupName) + + model := resp.Model + if model == nil { + return fmt.Errorf("reading Disk Encryption Set : %+v", err) } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) + if l := model.Location; l != "" { + d.Set("location", location.Normalize(l)) } - if props := resp.EncryptionSetProperties; props != nil { + if props := model.Properties; props != nil { keyVaultKeyId := "" - if props.ActiveKey != nil && props.ActiveKey.KeyURL != nil { - keyVaultKeyId = *props.ActiveKey.KeyURL + if props.ActiveKey != nil && props.ActiveKey.KeyUrl != "" { + keyVaultKeyId = props.ActiveKey.KeyUrl } d.Set("key_vault_key_id", keyVaultKeyId) d.Set("auto_key_rotation_enabled", props.RotationToLatestKeyVersionEnabled) - encryptionType := string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey) - if props.EncryptionType != "" { - encryptionType = string(props.EncryptionType) + encryptionType := string(diskencryptionsets.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey) + if props.EncryptionType != nil { + encryptionType = string(*props.EncryptionType) } d.Set("encryption_type", encryptionType) } - if err := d.Set("identity", flattenDiskEncryptionSetIdentity(resp.Identity)); err != nil { + flattenedIdentity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity) + if err != nil { + return fmt.Errorf("flattening `identity`: %+v", err) + } + + if err := d.Set("identity", flattenedIdentity); err != nil { return fmt.Errorf("setting `identity`: %+v", err) } - return tags.FlattenAndSet(d, resp.Tags) + return tags.FlattenAndSet(d, model.Tags) } func resourceDiskEncryptionSetUpdate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -221,12 +224,12 @@ func resourceDiskEncryptionSetUpdate(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.DiskEncryptionSetID(d.Id()) + id, err := diskencryptionsets.ParseDiskEncryptionSetID(d.Id()) if err != nil { return err } - update := compute.DiskEncryptionSetUpdate{} + update := diskencryptionsets.DiskEncryptionSetUpdate{} if d.HasChange("tags") { update.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } @@ -247,33 +250,30 @@ func resourceDiskEncryptionSetUpdate(d *pluginsdk.ResourceData, meta interface{} } } - update.DiskEncryptionSetUpdateProperties = &compute.DiskEncryptionSetUpdateProperties{ - ActiveKey: &compute.KeyForDiskEncryptionSet{ - KeyURL: utils.String(keyVaultKeyId), + update.Properties = &diskencryptionsets.DiskEncryptionSetUpdateProperties{ + ActiveKey: &diskencryptionsets.KeyForDiskEncryptionSet{ + KeyUrl: keyVaultKeyId, }, } if keyVaultDetails != nil { - update.DiskEncryptionSetUpdateProperties.ActiveKey.SourceVault = &compute.SourceVault{ - ID: utils.String(keyVaultDetails.keyVaultId), + update.Properties.ActiveKey.SourceVault = &diskencryptionsets.SourceVault{ + Id: utils.String(keyVaultDetails.keyVaultId), } } } if d.HasChange("auto_key_rotation_enabled") { - if update.DiskEncryptionSetUpdateProperties == nil { - update.DiskEncryptionSetUpdateProperties = &compute.DiskEncryptionSetUpdateProperties{} + if update.Properties == nil { + update.Properties = &diskencryptionsets.DiskEncryptionSetUpdateProperties{} } - update.DiskEncryptionSetUpdateProperties.RotationToLatestKeyVersionEnabled = utils.Bool(d.Get("auto_key_rotation_enabled").(bool)) + update.Properties.RotationToLatestKeyVersionEnabled = utils.Bool(d.Get("auto_key_rotation_enabled").(bool)) } - future, err := client.Update(ctx, id.ResourceGroup, id.Name, update) + err = client.UpdateThenPoll(ctx, *id, update) if err != nil { - return fmt.Errorf("updating Disk Encryption Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) - } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for update of Disk Encryption Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("updating Disk Encryption Set %q (Resource Group %q): %+v", id.DiskEncryptionSetName, id.ResourceGroupName, err) } return resourceDiskEncryptionSetRead(d, meta) @@ -284,50 +284,26 @@ func resourceDiskEncryptionSetDelete(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.DiskEncryptionSetID(d.Id()) + id, err := diskencryptionsets.ParseDiskEncryptionSetID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.Name) + err = client.DeleteThenPoll(ctx, *id) if err != nil { - return fmt.Errorf("deleting Disk Encryption Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deleting Disk Encryption Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) + return fmt.Errorf("deleting Disk Encryption Set %q (Resource Group %q): %+v", id.DiskEncryptionSetName, id.ResourceGroupName, err) } return nil } -func expandDiskEncryptionSetIdentity(input []interface{}) (*compute.EncryptionSetIdentity, error) { - expanded, err := identity.ExpandSystemAssigned(input) +func expandDiskEncryptionSetIdentity(input []interface{}) (*identity.SystemAndUserAssignedMap, error) { + expanded, err := identity.ExpandSystemAndUserAssignedMap(input) if err != nil { return nil, err } - return &compute.EncryptionSetIdentity{ - Type: compute.DiskEncryptionSetIdentityType(string(expanded.Type)), - }, nil -} - -func flattenDiskEncryptionSetIdentity(input *compute.EncryptionSetIdentity) []interface{} { - var transform *identity.SystemAssigned - - if input != nil { - transform = &identity.SystemAssigned{ - Type: identity.Type(string(input.Type)), - } - if input.PrincipalID != nil { - transform.PrincipalId = *input.PrincipalID - } - if input.TenantID != nil { - transform.TenantId = *input.TenantID - } - } - - return identity.FlattenSystemAssigned(transform) + return expanded, nil } type diskEncryptionSetKeyVault struct { diff --git a/internal/services/compute/disk_encryption_set_resource_test.go b/internal/services/compute/disk_encryption_set_resource_test.go index 8b000d38c647..7d0f39d7123b 100644 --- a/internal/services/compute/disk_encryption_set_resource_test.go +++ b/internal/services/compute/disk_encryption_set_resource_test.go @@ -5,10 +5,10 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -119,18 +119,53 @@ func TestAccDiskEncryptionSet_withEncryptionType(t *testing.T) { }) } +func TestAccDiskEncryptionSet_userAssignedIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_disk_encryption_set", "test") + r := DiskEncryptionSetResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.userAssignedIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDiskEncryptionSet_systemAssignedUserAssignedIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_disk_encryption_set", "test") + r := DiskEncryptionSetResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.systemAssignedUserAssignedIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func (DiskEncryptionSetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.DiskEncryptionSetID(state.ID) + id, err := diskencryptionsets.ParseDiskEncryptionSetID(state.ID) if err != nil { return nil, err } - resp, err := clients.Compute.DiskEncryptionSetsClient.Get(ctx, id.ResourceGroup, id.Name) + resp, err := clients.Compute.DiskEncryptionSetsClient.Get(ctx, *id) if err != nil { return nil, fmt.Errorf("retrieving Compute Disk Encryption Set %q", id.String()) } - return utils.Bool(resp.ID != nil), nil + model := resp.Model + if model == nil { + return nil, fmt.Errorf("retrieving Compute Disk Encryption Set %q: `model` was nil", id.String()) + } + + return utils.Bool(model.Id != nil), nil } func (DiskEncryptionSetResource) dependencies(data acceptance.TestData) string { @@ -201,6 +236,13 @@ resource "azurerm_key_vault_key" "test" { depends_on = ["azurerm_key_vault_access_policy.service-principal"] } +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func (r DiskEncryptionSetResource) systemAssignedDependencies(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + resource "azurerm_key_vault_access_policy" "disk-encryption" { key_vault_id = azurerm_key_vault.test.id @@ -212,8 +254,7 @@ resource "azurerm_key_vault_access_policy" "disk-encryption" { tenant_id = azurerm_disk_encryption_set.test.identity.0.tenant_id object_id = azurerm_disk_encryption_set.test.identity.0.principal_id -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString) +}`, r.dependencies(data)) } func (r DiskEncryptionSetResource) basic(data acceptance.TestData) string { @@ -230,7 +271,7 @@ resource "azurerm_disk_encryption_set" "test" { type = "SystemAssigned" } } -`, r.dependencies(data), data.RandomInteger) +`, r.systemAssignedDependencies(data), data.RandomInteger) } func (r DiskEncryptionSetResource) requiresImport(data acceptance.TestData) string { @@ -269,7 +310,7 @@ resource "azurerm_disk_encryption_set" "test" { Hello = "woRld" } } -`, r.dependencies(data), data.RandomInteger) +`, r.systemAssignedDependencies(data), data.RandomInteger) } func (r DiskEncryptionSetResource) keyRotate(data acceptance.TestData) string { @@ -305,7 +346,7 @@ resource "azurerm_disk_encryption_set" "test" { type = "SystemAssigned" } } -`, r.dependencies(data), data.RandomInteger) +`, r.systemAssignedDependencies(data), data.RandomInteger) } func (r DiskEncryptionSetResource) withPlatformAndCustomerKeys(data acceptance.TestData) string { @@ -323,5 +364,89 @@ resource "azurerm_disk_encryption_set" "test" { type = "SystemAssigned" } } -`, r.dependencies(data), data.RandomInteger) +`, r.systemAssignedDependencies(data), data.RandomInteger) +} + +func (r DiskEncryptionSetResource) userAssignedIdentity(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_user_assigned_identity" "test" { + name = "acctestUAI-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_key_vault_access_policy" "user-assigned" { + key_vault_id = azurerm_key_vault.test.id + tenant_id = azurerm_user_assigned_identity.test.tenant_id + object_id = azurerm_user_assigned_identity.test.principal_id + + key_permissions = [ + "Get", + "WrapKey", + "UnwrapKey", + ] + + depends_on = ["azurerm_key_vault_access_policy.service-principal"] +} + +resource "azurerm_disk_encryption_set" "test" { + name = "acctestDES-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + key_vault_key_id = azurerm_key_vault_key.test.id + + identity { + type = "UserAssigned" + identity_ids = [ + azurerm_user_assigned_identity.test.id, + ] + } + + depends_on = ["azurerm_key_vault_access_policy.user-assigned"] +} + `, r.dependencies(data), data.RandomInteger) +} + +func (r DiskEncryptionSetResource) systemAssignedUserAssignedIdentity(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_user_assigned_identity" "test" { + name = "acctestUAI-%[2]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_key_vault_access_policy" "user-assigned" { + key_vault_id = azurerm_key_vault.test.id + tenant_id = azurerm_user_assigned_identity.test.tenant_id + object_id = azurerm_user_assigned_identity.test.principal_id + + key_permissions = [ + "Get", + "WrapKey", + "UnwrapKey", + ] + + depends_on = ["azurerm_key_vault_access_policy.service-principal"] +} + +resource "azurerm_disk_encryption_set" "test" { + name = "acctestDES-%[2]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + key_vault_key_id = azurerm_key_vault_key.test.id + + identity { + type = "SystemAssigned, UserAssigned" + identity_ids = [ + azurerm_user_assigned_identity.test.id, + ] + } + + depends_on = ["azurerm_key_vault_access_policy.user-assigned"] +} + `, r.systemAssignedDependencies(data), data.RandomInteger) } diff --git a/internal/services/compute/linux_virtual_machine_resource.go b/internal/services/compute/linux_virtual_machine_resource.go index 4f2d7b7677c9..6e69f525c5d7 100644 --- a/internal/services/compute/linux_virtual_machine_resource.go +++ b/internal/services/compute/linux_virtual_machine_resource.go @@ -1390,7 +1390,7 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface update := compute.DiskUpdate{ DiskUpdateProperties: &compute.DiskUpdateProperties{ Encryption: &compute.Encryption{ - Type: *encryptionType, + Type: compute.EncryptionType(*encryptionType), DiskEncryptionSetID: utils.String(diskEncryptionSetId), }, }, diff --git a/internal/services/compute/managed_disk_resource.go b/internal/services/compute/managed_disk_resource.go index 82037cf3d45e..c58cee674fc2 100644 --- a/internal/services/compute/managed_disk_resource.go +++ b/internal/services/compute/managed_disk_resource.go @@ -407,7 +407,7 @@ func resourceManagedDiskCreate(d *pluginsdk.ResourceData, meta interface{}) erro } props.Encryption = &compute.Encryption{ - Type: *encryptionType, + Type: compute.EncryptionType(*encryptionType), DiskEncryptionSetID: utils.String(diskEncryptionSetId), } } @@ -667,7 +667,7 @@ func resourceManagedDiskUpdate(d *pluginsdk.ResourceData, meta interface{}) erro } diskUpdate.Encryption = &compute.Encryption{ - Type: *encryptionType, + Type: compute.EncryptionType(*encryptionType), DiskEncryptionSetID: utils.String(diskEncryptionSetId), } } else { diff --git a/internal/services/compute/windows_virtual_machine_resource.go b/internal/services/compute/windows_virtual_machine_resource.go index 0a4e8c017097..d7389a11b9db 100644 --- a/internal/services/compute/windows_virtual_machine_resource.go +++ b/internal/services/compute/windows_virtual_machine_resource.go @@ -1460,7 +1460,7 @@ func resourceWindowsVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interfa update := compute.DiskUpdate{ DiskUpdateProperties: &compute.DiskUpdateProperties{ Encryption: &compute.Encryption{ - Type: *encryptionType, + Type: compute.EncryptionType(*encryptionType), DiskEncryptionSetID: utils.String(diskEncryptionSetId), }, }, diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/README.md new file mode 100644 index 000000000000..c3248b22d159 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/README.md @@ -0,0 +1,133 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets` Documentation + +The `diskencryptionsets` SDK allows for interaction with the Azure Resource Manager Service `compute` (API Version `2022-03-02`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" +``` + + +### Client Initialization + +```go +client := diskencryptionsets.NewDiskEncryptionSetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DiskEncryptionSetsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewDiskEncryptionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskEncryptionSetValue") + +payload := diskencryptionsets.DiskEncryptionSet{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DiskEncryptionSetsClient.Delete` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewDiskEncryptionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskEncryptionSetValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DiskEncryptionSetsClient.Get` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewDiskEncryptionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskEncryptionSetValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DiskEncryptionSetsClient.List` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiskEncryptionSetsClient.ListAssociatedResources` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewDiskEncryptionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskEncryptionSetValue") + +// alternatively `client.ListAssociatedResources(ctx, id)` can be used to do batched pagination +items, err := client.ListAssociatedResourcesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiskEncryptionSetsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DiskEncryptionSetsClient.Update` + +```go +ctx := context.TODO() +id := diskencryptionsets.NewDiskEncryptionSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "diskEncryptionSetValue") + +payload := diskencryptionsets.DiskEncryptionSetUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/client.go new file mode 100644 index 000000000000..e0a2bccd661c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/client.go @@ -0,0 +1,18 @@ +package diskencryptionsets + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionSetsClient struct { + Client autorest.Client + baseUri string +} + +func NewDiskEncryptionSetsClientWithBaseURI(endpoint string) DiskEncryptionSetsClient { + return DiskEncryptionSetsClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/constants.go new file mode 100644 index 000000000000..b5454ff825fb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/constants.go @@ -0,0 +1,37 @@ +package diskencryptionsets + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionSetType string + +const ( + DiskEncryptionSetTypeConfidentialVmEncryptedWithCustomerKey DiskEncryptionSetType = "ConfidentialVmEncryptedWithCustomerKey" + DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey DiskEncryptionSetType = "EncryptionAtRestWithCustomerKey" + DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys DiskEncryptionSetType = "EncryptionAtRestWithPlatformAndCustomerKeys" +) + +func PossibleValuesForDiskEncryptionSetType() []string { + return []string{ + string(DiskEncryptionSetTypeConfidentialVmEncryptedWithCustomerKey), + string(DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey), + string(DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys), + } +} + +func parseDiskEncryptionSetType(input string) (*DiskEncryptionSetType, error) { + vals := map[string]DiskEncryptionSetType{ + "confidentialvmencryptedwithcustomerkey": DiskEncryptionSetTypeConfidentialVmEncryptedWithCustomerKey, + "encryptionatrestwithcustomerkey": DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey, + "encryptionatrestwithplatformandcustomerkeys": DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DiskEncryptionSetType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/id_diskencryptionset.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/id_diskencryptionset.go new file mode 100644 index 000000000000..5a0631c7273c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/id_diskencryptionset.go @@ -0,0 +1,124 @@ +package diskencryptionsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = DiskEncryptionSetId{} + +// DiskEncryptionSetId is a struct representing the Resource ID for a Disk Encryption Set +type DiskEncryptionSetId struct { + SubscriptionId string + ResourceGroupName string + DiskEncryptionSetName string +} + +// NewDiskEncryptionSetID returns a new DiskEncryptionSetId struct +func NewDiskEncryptionSetID(subscriptionId string, resourceGroupName string, diskEncryptionSetName string) DiskEncryptionSetId { + return DiskEncryptionSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DiskEncryptionSetName: diskEncryptionSetName, + } +} + +// ParseDiskEncryptionSetID parses 'input' into a DiskEncryptionSetId +func ParseDiskEncryptionSetID(input string) (*DiskEncryptionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(DiskEncryptionSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DiskEncryptionSetId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.DiskEncryptionSetName, ok = parsed.Parsed["diskEncryptionSetName"]; !ok { + return nil, fmt.Errorf("the segment 'diskEncryptionSetName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseDiskEncryptionSetIDInsensitively parses 'input' case-insensitively into a DiskEncryptionSetId +// note: this method should only be used for API response data and not user input +func ParseDiskEncryptionSetIDInsensitively(input string) (*DiskEncryptionSetId, error) { + parser := resourceids.NewParserFromResourceIdType(DiskEncryptionSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := DiskEncryptionSetId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.DiskEncryptionSetName, ok = parsed.Parsed["diskEncryptionSetName"]; !ok { + return nil, fmt.Errorf("the segment 'diskEncryptionSetName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateDiskEncryptionSetID checks that 'input' can be parsed as a Disk Encryption Set ID +func ValidateDiskEncryptionSetID(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 := ParseDiskEncryptionSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Disk Encryption Set ID +func (id DiskEncryptionSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/diskEncryptionSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DiskEncryptionSetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Disk Encryption Set ID +func (id DiskEncryptionSetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCompute", "Microsoft.Compute", "Microsoft.Compute"), + resourceids.StaticSegment("staticDiskEncryptionSets", "diskEncryptionSets", "diskEncryptionSets"), + resourceids.UserSpecifiedSegment("diskEncryptionSetName", "diskEncryptionSetValue"), + } +} + +// String returns a human-readable description of this Disk Encryption Set ID +func (id DiskEncryptionSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Disk Encryption Set Name: %q", id.DiskEncryptionSetName), + } + return fmt.Sprintf("Disk Encryption Set (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_createorupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_createorupdate_autorest.go new file mode 100644 index 000000000000..5f4b4abf27ad --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_createorupdate_autorest.go @@ -0,0 +1,79 @@ +package diskencryptionsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// CreateOrUpdate ... +func (c DiskEncryptionSetsClient) CreateOrUpdate(ctx context.Context, id DiskEncryptionSetId, input DiskEncryptionSet) (result CreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "CreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c DiskEncryptionSetsClient) CreateOrUpdateThenPoll(ctx context.Context, id DiskEncryptionSetId, input DiskEncryptionSet) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForCreateOrUpdate prepares the CreateOrUpdate request. +func (c DiskEncryptionSetsClient) preparerForCreateOrUpdate(ctx context.Context, id DiskEncryptionSetId, input DiskEncryptionSet) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForCreateOrUpdate sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c DiskEncryptionSetsClient) senderForCreateOrUpdate(ctx context.Context, req *http.Request) (future CreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_delete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_delete_autorest.go new file mode 100644 index 000000000000..4db9057b6029 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_delete_autorest.go @@ -0,0 +1,78 @@ +package diskencryptionsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Delete ... +func (c DiskEncryptionSetsClient) Delete(ctx context.Context, id DiskEncryptionSetId) (result DeleteOperationResponse, err error) { + req, err := c.preparerForDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Delete", nil, "Failure preparing request") + return + } + + result, err = c.senderForDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Delete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c DiskEncryptionSetsClient) DeleteThenPoll(ctx context.Context, id DiskEncryptionSetId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} + +// preparerForDelete prepares the Delete request. +func (c DiskEncryptionSetsClient) preparerForDelete(ctx context.Context, id DiskEncryptionSetId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForDelete sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (c DiskEncryptionSetsClient) senderForDelete(ctx context.Context, req *http.Request) (future DeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_get_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_get_autorest.go new file mode 100644 index 000000000000..cb595d235cba --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_get_autorest.go @@ -0,0 +1,68 @@ +package diskencryptionsets + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + Model *DiskEncryptionSet +} + +// Get ... +func (c DiskEncryptionSetsClient) Get(ctx context.Context, id DiskEncryptionSetId) (result GetOperationResponse, err error) { + req, err := c.preparerForGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Get", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Get", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Get", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForGet prepares the Get request. +func (c DiskEncryptionSetsClient) preparerForGet(ctx context.Context, id DiskEncryptionSetId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForGet handles the response to the Get request. The method always +// closes the http.Response Body. +func (c DiskEncryptionSetsClient) responderForGet(resp *http.Response) (result GetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_list_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_list_autorest.go new file mode 100644 index 000000000000..5d4c28314d7c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_list_autorest.go @@ -0,0 +1,187 @@ +package diskencryptionsets + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + Model *[]DiskEncryptionSet + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListOperationResponse, error) +} + +type ListCompleteResult struct { + Items []DiskEncryptionSet +} + +func (r ListOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListOperationResponse) LoadMore(ctx context.Context) (resp ListOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// List ... +func (c DiskEncryptionSetsClient) List(ctx context.Context, id commonids.SubscriptionId) (resp ListOperationResponse, err error) { + req, err := c.preparerForList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "List", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "List", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForList(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "List", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForList prepares the List request. +func (c DiskEncryptionSetsClient) preparerForList(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Compute/diskEncryptionSets", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListWithNextLink prepares the List request with the given nextLink token. +func (c DiskEncryptionSetsClient) preparerForListWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForList handles the response to the List request. The method always +// closes the http.Response Body. +func (c DiskEncryptionSetsClient) responderForList(resp *http.Response) (result ListOperationResponse, err error) { + type page struct { + Values []DiskEncryptionSet `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListOperationResponse, err error) { + req, err := c.preparerForListWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "List", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "List", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "List", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListComplete retrieves all of the results into a single object +func (c DiskEncryptionSetsClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DiskEncryptionSetOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c DiskEncryptionSetsClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DiskEncryptionSetOperationPredicate) (resp ListCompleteResult, err error) { + items := make([]DiskEncryptionSet, 0) + + page, err := c.List(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listassociatedresources_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listassociatedresources_autorest.go new file mode 100644 index 000000000000..04ad19a0f91e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listassociatedresources_autorest.go @@ -0,0 +1,177 @@ +package diskencryptionsets + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListAssociatedResourcesOperationResponse struct { + HttpResponse *http.Response + Model *[]string + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListAssociatedResourcesOperationResponse, error) +} + +type ListAssociatedResourcesCompleteResult struct { + Items []string +} + +func (r ListAssociatedResourcesOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListAssociatedResourcesOperationResponse) LoadMore(ctx context.Context) (resp ListAssociatedResourcesOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListAssociatedResources ... +func (c DiskEncryptionSetsClient) ListAssociatedResources(ctx context.Context, id DiskEncryptionSetId) (resp ListAssociatedResourcesOperationResponse, err error) { + req, err := c.preparerForListAssociatedResources(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListAssociatedResources", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListAssociatedResources", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListAssociatedResources(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListAssociatedResources", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListAssociatedResources prepares the ListAssociatedResources request. +func (c DiskEncryptionSetsClient) preparerForListAssociatedResources(ctx context.Context, id DiskEncryptionSetId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/associatedResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListAssociatedResourcesWithNextLink prepares the ListAssociatedResources request with the given nextLink token. +func (c DiskEncryptionSetsClient) preparerForListAssociatedResourcesWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListAssociatedResources handles the response to the ListAssociatedResources request. The method always +// closes the http.Response Body. +func (c DiskEncryptionSetsClient) responderForListAssociatedResources(resp *http.Response) (result ListAssociatedResourcesOperationResponse, err error) { + type page struct { + Values []string `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListAssociatedResourcesOperationResponse, err error) { + req, err := c.preparerForListAssociatedResourcesWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListAssociatedResources", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListAssociatedResources", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListAssociatedResources(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListAssociatedResources", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListAssociatedResourcesComplete retrieves all of the results into a single object +func (c DiskEncryptionSetsClient) ListAssociatedResourcesComplete(ctx context.Context, id DiskEncryptionSetId) (result ListAssociatedResourcesCompleteResult, err error) { + items := make([]string, 0) + + page, err := c.ListAssociatedResources(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + items = append(items, v) + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + items = append(items, v) + } + } + } + + out := ListAssociatedResourcesCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listbyresourcegroup_autorest.go new file mode 100644 index 000000000000..15e17aeeacce --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_listbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package diskencryptionsets + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]DiskEncryptionSet + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ListByResourceGroupOperationResponse, error) +} + +type ListByResourceGroupCompleteResult struct { + Items []DiskEncryptionSet +} + +func (r ListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ListByResourceGroup ... +func (c DiskEncryptionSetsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForListByResourceGroup prepares the ListByResourceGroup request. +func (c DiskEncryptionSetsClient) preparerForListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Compute/diskEncryptionSets", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForListByResourceGroupWithNextLink prepares the ListByResourceGroup request with the given nextLink token. +func (c DiskEncryptionSetsClient) preparerForListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForListByResourceGroup handles the response to the ListByResourceGroup request. The method always +// closes the http.Response Body. +func (c DiskEncryptionSetsClient) responderForListByResourceGroup(resp *http.Response) (result ListByResourceGroupOperationResponse, err error) { + type page struct { + Values []DiskEncryptionSet `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "ListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ListByResourceGroupComplete retrieves all of the results into a single object +func (c DiskEncryptionSetsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, DiskEncryptionSetOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c DiskEncryptionSetsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate DiskEncryptionSetOperationPredicate) (resp ListByResourceGroupCompleteResult, err error) { + items := make([]DiskEncryptionSet, 0) + + page, err := c.ListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_update_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_update_autorest.go new file mode 100644 index 000000000000..554b33ddce30 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/method_update_autorest.go @@ -0,0 +1,79 @@ +package diskencryptionsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// Update ... +func (c DiskEncryptionSetsClient) Update(ctx context.Context, id DiskEncryptionSetId, input DiskEncryptionSetUpdate) (result UpdateOperationResponse, err error) { + req, err := c.preparerForUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Update", nil, "Failure preparing request") + return + } + + result, err = c.senderForUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "diskencryptionsets.DiskEncryptionSetsClient", "Update", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c DiskEncryptionSetsClient) UpdateThenPoll(ctx context.Context, id DiskEncryptionSetId, input DiskEncryptionSetUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} + +// preparerForUpdate prepares the Update request. +func (c DiskEncryptionSetsClient) preparerForUpdate(ctx context.Context, id DiskEncryptionSetId, input DiskEncryptionSetUpdate) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForUpdate sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (c DiskEncryptionSetsClient) senderForUpdate(ctx context.Context, req *http.Request) (future UpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierror.go new file mode 100644 index 000000000000..429fbf73e783 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierror.go @@ -0,0 +1,12 @@ +package diskencryptionsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiError struct { + Code *string `json:"code,omitempty"` + Details *[]ApiErrorBase `json:"details,omitempty"` + Innererror *InnerError `json:"innererror,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierrorbase.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierrorbase.go new file mode 100644 index 000000000000..a5cff4f11fd5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_apierrorbase.go @@ -0,0 +1,10 @@ +package diskencryptionsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiErrorBase struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` + Target *string `json:"target,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionset.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionset.go new file mode 100644 index 000000000000..729a73bc790b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionset.go @@ -0,0 +1,18 @@ +package diskencryptionsets + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionSet struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *EncryptionSetProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdate.go new file mode 100644 index 000000000000..9b426eb34b87 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdate.go @@ -0,0 +1,14 @@ +package diskencryptionsets + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionSetUpdate struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *DiskEncryptionSetUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdateproperties.go new file mode 100644 index 000000000000..19afb3106e5e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_diskencryptionsetupdateproperties.go @@ -0,0 +1,11 @@ +package diskencryptionsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DiskEncryptionSetUpdateProperties struct { + ActiveKey *KeyForDiskEncryptionSet `json:"activeKey,omitempty"` + EncryptionType *DiskEncryptionSetType `json:"encryptionType,omitempty"` + FederatedClientId *string `json:"federatedClientId,omitempty"` + RotationToLatestKeyVersionEnabled *bool `json:"rotationToLatestKeyVersionEnabled,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_encryptionsetproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_encryptionsetproperties.go new file mode 100644 index 000000000000..485a88b63a65 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_encryptionsetproperties.go @@ -0,0 +1,33 @@ +package diskencryptionsets + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionSetProperties struct { + ActiveKey *KeyForDiskEncryptionSet `json:"activeKey,omitempty"` + AutoKeyRotationError *ApiError `json:"autoKeyRotationError,omitempty"` + EncryptionType *DiskEncryptionSetType `json:"encryptionType,omitempty"` + FederatedClientId *string `json:"federatedClientId,omitempty"` + LastKeyRotationTimestamp *string `json:"lastKeyRotationTimestamp,omitempty"` + PreviousKeys *[]KeyForDiskEncryptionSet `json:"previousKeys,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + RotationToLatestKeyVersionEnabled *bool `json:"rotationToLatestKeyVersionEnabled,omitempty"` +} + +func (o *EncryptionSetProperties) GetLastKeyRotationTimestampAsTime() (*time.Time, error) { + if o.LastKeyRotationTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastKeyRotationTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *EncryptionSetProperties) SetLastKeyRotationTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastKeyRotationTimestamp = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_innererror.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_innererror.go new file mode 100644 index 000000000000..576cfe901f7e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_innererror.go @@ -0,0 +1,9 @@ +package diskencryptionsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type InnerError struct { + Errordetail *string `json:"errordetail,omitempty"` + Exceptiontype *string `json:"exceptiontype,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_keyfordiskencryptionset.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_keyfordiskencryptionset.go new file mode 100644 index 000000000000..bfc2790b5805 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_keyfordiskencryptionset.go @@ -0,0 +1,9 @@ +package diskencryptionsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyForDiskEncryptionSet struct { + KeyUrl string `json:"keyUrl"` + SourceVault *SourceVault `json:"sourceVault,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_sourcevault.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_sourcevault.go new file mode 100644 index 000000000000..6e0c177c3113 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/model_sourcevault.go @@ -0,0 +1,8 @@ +package diskencryptionsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SourceVault struct { + Id *string `json:"id,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/predicates.go new file mode 100644 index 000000000000..ee72503cc958 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/predicates.go @@ -0,0 +1,29 @@ +package diskencryptionsets + +type DiskEncryptionSetOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DiskEncryptionSetOperationPredicate) Matches(input DiskEncryptionSet) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/version.go new file mode 100644 index 000000000000..172f878f2fb0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets/version.go @@ -0,0 +1,12 @@ +package diskencryptionsets + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-03-02" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/diskencryptionsets/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 0aa136fa756f..1aae269e116a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -204,6 +204,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedh github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedhosts github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/proximityplacementgroups github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/sshpublickeys +github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets github.com/hashicorp/go-azure-sdk/resource-manager/confidentialledger/2022-05-13/confidentialledger github.com/hashicorp/go-azure-sdk/resource-manager/consumption/2019-10-01/budgets github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-03-01/containerinstance diff --git a/website/docs/r/disk_encryption_set.html.markdown b/website/docs/r/disk_encryption_set.html.markdown index 2067bc3ae308..49c5d27a078a 100644 --- a/website/docs/r/disk_encryption_set.html.markdown +++ b/website/docs/r/disk_encryption_set.html.markdown @@ -137,7 +137,11 @@ In this case, `azurerm_key_vault_access_policy` is not needed. An `identity` block supports the following: -* `type` - (Required) The type of Managed Service Identity that is configured on this Disk Encryption Set. The only possible value is `SystemAssigned`. +* `type` - (Required) The type of Managed Service Identity that is configured on this Disk Encryption Set. Possible values are `SystemAssigned`, `UserAssigned`, `SystemAssigned, UserAssigned` (to enable both). + +* `identity_ids` - (Optional) A list of User Assigned Managed Identity IDs to be assigned to this Disk Encryption Set. + +~> **NOTE:** This is required when `type` is set to `UserAssigned` or `SystemAssigned, UserAssigned`. ## Attributes Reference From 2ff49e12ad1432cc45698753108b3ce734e707ea Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Mon, 26 Sep 2022 13:19:44 +0800 Subject: [PATCH 2/6] resolve merge issue --- internal/services/compute/disk_encryption_set.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/services/compute/disk_encryption_set.go b/internal/services/compute/disk_encryption_set.go index 867f7ef23e1e..83c11e94f21a 100644 --- a/internal/services/compute/disk_encryption_set.go +++ b/internal/services/compute/disk_encryption_set.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" + "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks" ) // retrieveDiskEncryptionSetEncryptionType returns encryption type of the disk encryption set @@ -19,11 +19,12 @@ func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *disken if err != nil { return nil, fmt.Errorf("retrieving %s: %+v", *id, err) } - var encryptionType *diskencryptionsets.DiskEncryptionSetType + var encryptionType *disks.EncryptionType if model := resp.Model; model != nil { if props := model.Properties; props != nil && props.EncryptionType != nil { - v := disks.EncryptionType(props.EncryptionType.(string)) + s := props.EncryptionType + v := disks.EncryptionType(*s) encryptionType = &v } } From ff60d6aa20ad4fa843272f1f59d505dbc1d7088f Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Mon, 26 Sep 2022 13:20:07 +0800 Subject: [PATCH 3/6] refresh vendor --- vendor/modules.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/vendor/modules.txt b/vendor/modules.txt index 565516490fc0..989d9bbaf209 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -205,6 +205,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedh github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/dedicatedhosts github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/proximityplacementgroups github.com/hashicorp/go-azure-sdk/resource-manager/compute/2021-11-01/sshpublickeys +github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/disks github.com/hashicorp/go-azure-sdk/resource-manager/confidentialledger/2022-05-13/confidentialledger github.com/hashicorp/go-azure-sdk/resource-manager/consumption/2019-10-01/budgets From 2de7eb0807daf3fe5defb97ea2fc63e72dfa57f6 Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Thu, 27 Oct 2022 10:26:56 +0800 Subject: [PATCH 4/6] doc: add note --- website/docs/r/disk_encryption_set.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/docs/r/disk_encryption_set.html.markdown b/website/docs/r/disk_encryption_set.html.markdown index 49c5d27a078a..d667cd520750 100644 --- a/website/docs/r/disk_encryption_set.html.markdown +++ b/website/docs/r/disk_encryption_set.html.markdown @@ -137,7 +137,9 @@ In this case, `azurerm_key_vault_access_policy` is not needed. An `identity` block supports the following: -* `type` - (Required) The type of Managed Service Identity that is configured on this Disk Encryption Set. Possible values are `SystemAssigned`, `UserAssigned`, `SystemAssigned, UserAssigned` (to enable both). +* `type` - (Required) The type of Managed Service Identity that is configured on this Disk Encryption Set. Possible values are `SystemAssigned`, `UserAssigned`, `SystemAssigned, UserAssigned` (to enable both). + +* -> **Note:** Before setting `type` to `UserAssigned`, `SystemAssigned, UserAssigned`, it's required to enable the feature with Azure CLI `az feature register --namespace Microsoft.Compute --name EncryptionAtRestWithCrossTenantKey` then `az provider register -n Microsoft.Compute`. See more details from https://learn.microsoft.com/en-us/azure/virtual-machines/disks-cross-tenant-customer-managed-keys. * `identity_ids` - (Optional) A list of User Assigned Managed Identity IDs to be assigned to this Disk Encryption Set. From df2b55fe5c449f03b33698ae19893674cc7998f3 Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Thu, 27 Oct 2022 10:44:37 +0800 Subject: [PATCH 5/6] golint --- internal/services/compute/disk_encryption_set_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/compute/disk_encryption_set_resource.go b/internal/services/compute/disk_encryption_set_resource.go index 85bd6815e280..cb9e92760426 100644 --- a/internal/services/compute/disk_encryption_set_resource.go +++ b/internal/services/compute/disk_encryption_set_resource.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/diskencryptionsets" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" From f7cc82ce3f313bae830f5301f8db5658f42cea61 Mon Sep 17 00:00:00 2001 From: ziyeqf Date: Thu, 27 Oct 2022 15:43:43 +0800 Subject: [PATCH 6/6] resolve merge issue --- internal/services/compute/disk_encryption_set_resource.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/compute/disk_encryption_set_resource.go b/internal/services/compute/disk_encryption_set_resource.go index 44c87d6c58e7..078fab03824b 100644 --- a/internal/services/compute/disk_encryption_set_resource.go +++ b/internal/services/compute/disk_encryption_set_resource.go @@ -146,11 +146,11 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} if keyVaultDetails != nil { params.Properties.ActiveKey.SourceVault = &diskencryptionsets.SourceVault{ - Id: utils.String(keyVaultDetails.keyVaultId), - } + Id: utils.String(keyVaultDetails.keyVaultId), + } } - future, err := client.CreateOrUpdate(ctx, id, params) + err = client.CreateOrUpdateThenPoll(ctx, id, params) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) }