Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
myc2h6o committed Nov 18, 2021
1 parent 10e9b6d commit 9d35598
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 52 deletions.
19 changes: 12 additions & 7 deletions internal/services/compute/disk_encryption_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ import (
)

// retrieveDiskEncryptionSetEncryptionType returns encryption type of the disk encryption set
func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *compute.DiskEncryptionSetsClient, diskEncryptionSetId string) (*string, error) {
func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *compute.DiskEncryptionSetsClient, diskEncryptionSetId string) (*compute.EncryptionType, error) {
diskEncryptionSet, err := parse.DiskEncryptionSetID(diskEncryptionSetId)
if err != nil {
return nil, err
}

resp, err := client.Get(ctx, diskEncryptionSet.ResourceGroup, diskEncryptionSet.Name)
if err != nil {
return nil, err
return nil, fmt.Errorf("retrieving %s: %+v", *diskEncryptionSet, err)
}

var encryptionType *compute.EncryptionType
if props := resp.EncryptionSetProperties; props != nil && string(props.EncryptionType) != "" {
v := compute.EncryptionType(props.EncryptionType)
encryptionType = &v
}

if properties := resp.EncryptionSetProperties; properties != nil {
encryptionType := string(properties.EncryptionType)
return &encryptionType, nil
} else {
return nil, fmt.Errorf("could not get EncryptionSetProperties")
if encryptionType == nil {
return nil, fmt.Errorf("retrieving %s: EncryptionType was nil", *diskEncryptionSet)
}

return encryptionType, nil
}
11 changes: 8 additions & 3 deletions internal/services/compute/disk_encryption_set_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func resourceDiskEncryptionSet() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey,
Default: string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey),
ValidateFunc: validation.StringInSlice([]string{
string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey),
string(compute.DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys),
}, true),
}, false),
},

"identity": {
Expand Down Expand Up @@ -216,7 +216,12 @@ func resourceDiskEncryptionSetRead(d *pluginsdk.ResourceData, meta interface{})
}
d.Set("key_vault_key_id", keyVaultKeyId)
d.Set("auto_key_rotation_enabled", props.RotationToLatestKeyVersionEnabled)
d.Set("encryption_type", props.EncryptionType)

encryptionType := string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey)
if props.EncryptionType != "" {
encryptionType = string(props.EncryptionType)
}
d.Set("encryption_type", encryptionType)
}

if err := d.Set("identity", flattenDiskEncryptionSetIdentity(resp.Identity)); err != nil {
Expand Down
31 changes: 3 additions & 28 deletions internal/services/compute/disk_encryption_set_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccDiskEncryptionSet_basic(t *testing.T) {
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("encryption_type").HasValue("EncryptionAtRestWithCustomerKey"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -110,18 +111,9 @@ func TestAccDiskEncryptionSet_withEncryptionType(t *testing.T) {

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withEncryptionTypeDefault(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("encryption_type").HasValue("EncryptionAtRestWithCustomerKey"),
),
},
data.ImportStep(),
{
Config: r.withEncryptionTypeUpdated(data),
Config: r.withPlatformAndCustomerKeys(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("encryption_type").HasValue("EncryptionAtRestWithPlatformAndCustomerKeys"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -317,24 +309,7 @@ resource "azurerm_disk_encryption_set" "test" {
`, r.dependencies(data), data.RandomInteger)
}

func (r DiskEncryptionSetResource) withEncryptionTypeDefault(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_disk_encryption_set" "test" {
name = "acctestDES-%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"
}
}
`, r.dependencies(data), data.RandomInteger)
}

func (r DiskEncryptionSetResource) withEncryptionTypeUpdated(data acceptance.TestData) string {
func (r DiskEncryptionSetResource) withPlatformAndCustomerKeys(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
4 changes: 2 additions & 2 deletions internal/services/compute/linux_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,15 +1091,15 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface

encryptionType, err := retrieveDiskEncryptionSetEncryptionType(ctx, meta.(*clients.Client).Compute.DiskEncryptionSetsClient, diskEncryptionSetId)
if err != nil {
return fmt.Errorf("retrieving encryption type from disk encryption set %q: %+v", diskEncryptionSetId, err)
return err
}

disksClient := meta.(*clients.Client).Compute.DisksClient

update := compute.DiskUpdate{
DiskUpdateProperties: &compute.DiskUpdateProperties{
Encryption: &compute.Encryption{
Type: compute.EncryptionType(*encryptionType),
Type: *encryptionType,
DiskEncryptionSetID: utils.String(diskEncryptionSetId),
},
},
Expand Down
6 changes: 3 additions & 3 deletions internal/services/compute/managed_disk_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ func resourceManagedDiskCreate(d *pluginsdk.ResourceData, meta interface{}) erro
if diskEncryptionSetId := d.Get("disk_encryption_set_id").(string); diskEncryptionSetId != "" {
encryptionType, err := retrieveDiskEncryptionSetEncryptionType(ctx, meta.(*clients.Client).Compute.DiskEncryptionSetsClient, diskEncryptionSetId)
if err != nil {
return fmt.Errorf("retrieving encryption type from disk encryption set %q: %+v", diskEncryptionSetId, err)
return err
}

props.Encryption = &compute.Encryption{
Type: compute.EncryptionType(*encryptionType),
Type: *encryptionType,
DiskEncryptionSetID: utils.String(diskEncryptionSetId),
}
}
Expand Down Expand Up @@ -544,7 +544,7 @@ func resourceManagedDiskUpdate(d *pluginsdk.ResourceData, meta interface{}) erro
if diskEncryptionSetId := d.Get("disk_encryption_set_id").(string); diskEncryptionSetId != "" {
encryptionType, err := retrieveDiskEncryptionSetEncryptionType(ctx, meta.(*clients.Client).Compute.DiskEncryptionSetsClient, diskEncryptionSetId)
if err != nil {
return fmt.Errorf("retrieving encryption type from disk encryption set %q: %+v", diskEncryptionSetId, err)
return err
}

diskUpdate.Encryption = &compute.Encryption{
Expand Down
4 changes: 2 additions & 2 deletions internal/services/compute/windows_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1128,15 +1128,15 @@ func resourceWindowsVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interfa

encryptionType, err := retrieveDiskEncryptionSetEncryptionType(ctx, meta.(*clients.Client).Compute.DiskEncryptionSetsClient, diskEncryptionSetId)
if err != nil {
return fmt.Errorf("retrieving encryption type from disk encryption set %q: %+v", diskEncryptionSetId, err)
return err
}

disksClient := meta.(*clients.Client).Compute.DisksClient

update := compute.DiskUpdate{
DiskUpdateProperties: &compute.DiskUpdateProperties{
Encryption: &compute.Encryption{
Type: compute.EncryptionType(*encryptionType),
Type: *encryptionType,
DiskEncryptionSetID: utils.String(diskEncryptionSetId),
},
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/disk_encryption_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The following arguments are supported:

* `auto_key_rotation_enabled` - (Optional) Boolean flag to specify whether Azure Disk Encryption Set automatically rotates encryption Key to latest version. Defaults to `false`.

* `encryption_type` - (Optional) The type of key used to encrypt the data of the disk. Allowed values are `EncryptionAtRestWithCustomerKey` and `EncryptionAtRestWithPlatformAndCustomerKeys`. Defaults to `EncryptionAtRestWithCustomerKey`.
* `encryption_type` - (Optional) The type of key used to encrypt the data of the disk. Possible values are `EncryptionAtRestWithCustomerKey` and `EncryptionAtRestWithPlatformAndCustomerKeys`. Defaults to `EncryptionAtRestWithCustomerKey`.

* `identity` - (Required) An `identity` block as defined below.

Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/linux_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ A `os_disk` block supports the following:

-> **NOTE:** The Disk Encryption Set must have the `Reader` Role Assignment scoped on the Key Vault - in addition to an Access Policy to the Key Vault

-> **NOTE:** Encryption type of the key will be decided by the disk encryption set. [More info on encryption type](https://docs.microsoft.com/en-us/azure/virtual-machines/disk-encryption)

* `disk_size_gb` - (Optional) The Size of the Internal OS Disk in GB, if you wish to vary from the size used in the image this Virtual Machine is sourced from.

-> **NOTE:** If specified this must be equal to or larger than the size of the Image the Virtual Machine is based on. When creating a larger disk than exists in the image you'll need to repartition the disk to use the remaining space.
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/managed_disk.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ The following arguments are supported:

~> **NOTE:** Disk Encryption Sets are in Public Preview in a limited set of regions

-> **NOTE:** Encryption type of the key will be decided by the disk encryption set. [More info on encryption type](https://docs.microsoft.com/en-us/azure/virtual-machines/disk-encryption)

* `disk_iops_read_write` - (Optional) The number of IOPS allowed for this disk; only settable for UltraSSD disks. One operation can transfer between 4k and 256k bytes.

* `disk_mbps_read_write` - (Optional) The bandwidth allowed for this disk; only settable for UltraSSD disks. MBps means millions of bytes per second.
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/windows_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,6 @@ A `os_disk` block supports the following:

-> **NOTE:** The Disk Encryption Set must have the `Reader` Role Assignment scoped on the Key Vault - in addition to an Access Policy to the Key Vault

-> **NOTE:** Encryption type of the key will be decided by the disk encryption set. [More info on encryption type](https://docs.microsoft.com/en-us/azure/virtual-machines/disk-encryption)

* `disk_size_gb` - (Optional) The Size of the Internal OS Disk in GB, if you wish to vary from the size used in the image this Virtual Machine is sourced from.

-> **NOTE:** If specified this must be equal to or larger than the size of the Image the Virtual Machine is based on. When creating a larger disk than exists in the image you'll need to repartition the disk to use the remaining space.
Expand Down

0 comments on commit 9d35598

Please sign in to comment.