Skip to content

Commit

Permalink
azurerm_disk_encryption_set - identity support for UserAssigned
Browse files Browse the repository at this point in the history
… and `SystemUserAssgined` identity (#18525)
  • Loading branch information
ziyeqf authored Oct 28, 2022
1 parent cfa6ad1 commit 2a79fca
Show file tree
Hide file tree
Showing 29 changed files with 1,574 additions and 127 deletions.
5 changes: 3 additions & 2 deletions internal/services/compute/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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/go-azure-sdk/resource-manager/compute/2022-03-02/disks"
"github.com/hashicorp/go-azure-sdk/resource-manager/compute/2022-03-02/snapshots"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
Expand All @@ -21,7 +22,7 @@ type Client struct {
DedicatedHostGroupsClient *dedicatedhostgroups.DedicatedHostGroupsClient
DisksClient *disks.DisksClient
DiskAccessClient *compute.DiskAccessesClient
DiskEncryptionSetsClient *compute.DiskEncryptionSetsClient
DiskEncryptionSetsClient *diskencryptionsets.DiskEncryptionSetsClient
GalleriesClient *compute.GalleriesClient
GalleryApplicationsClient *compute.GalleryApplicationsClient
GalleryApplicationVersionsClient *compute.GalleryApplicationVersionsClient
Expand Down Expand Up @@ -65,7 +66,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)
Expand Down
24 changes: 13 additions & 11 deletions internal/services/compute/disk_encryption_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ import (
"context"
"fmt"

"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/terraform-provider-azurerm/internal/services/compute/parse"
"github.com/tombuildsstuff/kermit/sdk/compute/2022-08-01/compute"
)

// retrieveDiskEncryptionSetEncryptionType returns encryption type of the disk encryption set
func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *compute.DiskEncryptionSetsClient, diskEncryptionSetId string) (*disks.EncryptionType, error) {
diskEncryptionSet, err := parse.DiskEncryptionSetID(diskEncryptionSetId)
func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *diskencryptionsets.DiskEncryptionSetsClient, diskEncryptionSetId string) (*disks.EncryptionType, 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 *disks.EncryptionType
if props := resp.EncryptionSetProperties; props != nil && string(props.EncryptionType) != "" {
v := disks.EncryptionType(props.EncryptionType)
encryptionType = &v

if model := resp.Model; model != nil {
if props := model.Properties; props != nil && props.EncryptionType != nil {
s := props.EncryptionType
v := disks.EncryptionType(*s)
encryptionType = &v
}
}

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
Expand Down
26 changes: 14 additions & 12 deletions internal/services/compute/disk_encryption_set_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -39,7 +40,7 @@ func dataSourceDiskEncryptionSet() *pluginsdk.Resource {
Computed: true,
},

"tags": tags.SchemaDataSource(),
"tags": commonschema.TagsDataSource(),
},
}
}
Expand All @@ -50,26 +51,27 @@ 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)
}

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)
}
Loading

0 comments on commit 2a79fca

Please sign in to comment.