-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support EncryptionAtRestWithPlatformAndCustomerKeys
in disk encryption
#14218
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||
package compute | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-07-01/compute" | ||||||||||||||||||||||||||||||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/compute/parse" | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// retrieveDiskEncryptionSetEncryptionType returns encryption type of the disk encryption set | ||||||||||||||||||||||||||||||||||
func retrieveDiskEncryptionSetEncryptionType(ctx context.Context, client *compute.DiskEncryptionSetsClient, diskEncryptionSetId string) (*string, 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 | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to specify an error occurred while attempting to retrieve a disk encryption set
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes make sense, adding |
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if properties := resp.EncryptionSetProperties; properties != nil { | ||||||||||||||||||||||||||||||||||
encryptionType := string(properties.EncryptionType) | ||||||||||||||||||||||||||||||||||
return &encryptionType, nil | ||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("could not get EncryptionSetProperties") | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should become:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -65,6 +65,17 @@ func resourceDiskEncryptionSet() *pluginsdk.Resource { | |||||||||||||
Optional: true, | ||||||||||||||
}, | ||||||||||||||
|
||||||||||||||
"encryption_type": { | ||||||||||||||
Type: pluginsdk.TypeString, | ||||||||||||||
Optional: true, | ||||||||||||||
ForceNew: true, | ||||||||||||||
Default: compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a string:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for pointing out, updated |
||||||||||||||
ValidateFunc: validation.StringInSlice([]string{ | ||||||||||||||
string(compute.DiskEncryptionSetTypeEncryptionAtRestWithCustomerKey), | ||||||||||||||
string(compute.DiskEncryptionSetTypeEncryptionAtRestWithPlatformAndCustomerKeys), | ||||||||||||||
}, true), | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be case-sensitive:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||||||||||
}, | ||||||||||||||
|
||||||||||||||
"identity": { | ||||||||||||||
Type: pluginsdk.TypeList, | ||||||||||||||
// whilst the API Documentation shows optional - attempting to send nothing returns: | ||||||||||||||
|
@@ -132,6 +143,7 @@ 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) | ||||||||||||||
identityRaw := d.Get("identity").([]interface{}) | ||||||||||||||
t := d.Get("tags").(map[string]interface{}) | ||||||||||||||
|
||||||||||||||
|
@@ -145,6 +157,7 @@ func resourceDiskEncryptionSetCreate(d *pluginsdk.ResourceData, meta interface{} | |||||||||||||
}, | ||||||||||||||
}, | ||||||||||||||
RotationToLatestKeyVersionEnabled: utils.Bool(rotationToLatestKeyVersionEnabled), | ||||||||||||||
EncryptionType: compute.DiskEncryptionSetType(encryptionType), | ||||||||||||||
}, | ||||||||||||||
Identity: expandDiskEncryptionSetIdentity(identityRaw), | ||||||||||||||
Tags: tags.Expand(t), | ||||||||||||||
|
@@ -203,6 +216,7 @@ 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) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this won't be returned from the API for older resources - so we'll need to default that in code:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to set default value |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if err := d.Set("identity", flattenDiskEncryptionSetIdentity(resp.Identity)); err != nil { | ||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -104,6 +104,30 @@ func TestAccDiskEncryptionSet_keyRotate(t *testing.T) { | |||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func TestAccDiskEncryptionSet_withEncryptionType(t *testing.T) { | ||||||||||||||||||||||||||||||||||
data := acceptance.BuildTestData(t, "azurerm_disk_encryption_set", "test") | ||||||||||||||||||||||||||||||||||
r := DiskEncryptionSetResource{} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
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), | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this field is ForceNew, so this won't update - it'll destroy and recreate the resource. Since the first step is the same as
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes make sense, removed the update part in the test and add the default value check to the basic test |
||||||||||||||||||||||||||||||||||
Check: acceptance.ComposeTestCheckFunc( | ||||||||||||||||||||||||||||||||||
check.That(data.ResourceName).ExistsInAzure(r), | ||||||||||||||||||||||||||||||||||
check.That(data.ResourceName).Key("encryption_type").HasValue("EncryptionAtRestWithPlatformAndCustomerKeys"), | ||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||
data.ImportStep(), | ||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func (DiskEncryptionSetResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { | ||||||||||||||||||||||||||||||||||
id, err := parse.DiskEncryptionSetID(state.ID) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
|
@@ -292,3 +316,38 @@ 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) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the same as Basic so can go:
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
func (r DiskEncryptionSetResource) withEncryptionTypeUpdated(data acceptance.TestData) string { | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||
encryption_type = "EncryptionAtRestWithPlatformAndCustomerKeys" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
identity { | ||||||||||||||||||||||||||||||||||
type = "SystemAssigned" | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
`, r.dependencies(data), data.RandomInteger) | ||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1089,12 +1089,17 @@ func resourceLinuxVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interface | |||||
diskName := d.Get("os_disk.0.name").(string) | ||||||
log.Printf("[DEBUG] Updating encryption settings of OS Disk %q for Linux Virtual Machine %q (Resource Group %q) to %q..", diskName, id.Name, id.ResourceGroup, 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then here to just return the error
Suggested change
|
||||||
} | ||||||
|
||||||
disksClient := meta.(*clients.Client).Compute.DisksClient | ||||||
|
||||||
update := compute.DiskUpdate{ | ||||||
DiskUpdateProperties: &compute.DiskUpdateProperties{ | ||||||
Encryption: &compute.Encryption{ | ||||||
Type: compute.EncryptionTypeEncryptionAtRestWithCustomerKey, | ||||||
Type: compute.EncryptionType(*encryptionType), | ||||||
DiskEncryptionSetID: utils.String(diskEncryptionSetId), | ||||||
}, | ||||||
}, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -167,7 +167,7 @@ func resourceManagedDisk() *pluginsdk.Resource { | |||||
// TODO: make this case-sensitive once this bug in the Azure API has been fixed: | ||||||
// https://github.com/Azure/azure-rest-api-specs/issues/8132 | ||||||
DiffSuppressFunc: suppress.CaseDifference, | ||||||
ValidateFunc: azure.ValidateResourceID, | ||||||
ValidateFunc: validate.DiskEncryptionSetID, | ||||||
}, | ||||||
|
||||||
"encryption_settings": encryptionSettingsSchema(), | ||||||
|
@@ -344,8 +344,13 @@ 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||||
} | ||||||
|
||||||
props.Encryption = &compute.Encryption{ | ||||||
Type: compute.EncryptionTypeEncryptionAtRestWithCustomerKey, | ||||||
Type: compute.EncryptionType(*encryptionType), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why doesn't the method above return
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return type updated |
||||||
DiskEncryptionSetID: utils.String(diskEncryptionSetId), | ||||||
} | ||||||
} | ||||||
|
@@ -537,8 +542,13 @@ func resourceManagedDiskUpdate(d *pluginsdk.ResourceData, meta interface{}) erro | |||||
if d.HasChange("disk_encryption_set_id") { | ||||||
shouldShutDown = true | ||||||
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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||||
} | ||||||
|
||||||
diskUpdate.Encryption = &compute.Encryption{ | ||||||
Type: compute.EncryptionTypeEncryptionAtRestWithCustomerKey, | ||||||
Type: compute.EncryptionType(*encryptionType), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here:
Suggested change
|
||||||
DiskEncryptionSetID: utils.String(diskEncryptionSetId), | ||||||
} | ||||||
} else { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1126,12 +1126,17 @@ func resourceWindowsVirtualMachineUpdate(d *pluginsdk.ResourceData, meta interfa | |||||
diskName := d.Get("os_disk.0.name").(string) | ||||||
log.Printf("[DEBUG] Updating encryption settings of OS Disk %q for Windows Virtual Machine %q (Resource Group %q) to %q..", diskName, id.Name, id.ResourceGroup, 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||||||
} | ||||||
|
||||||
disksClient := meta.(*clients.Client).Compute.DisksClient | ||||||
|
||||||
update := compute.DiskUpdate{ | ||||||
DiskUpdateProperties: &compute.DiskUpdateProperties{ | ||||||
Encryption: &compute.Encryption{ | ||||||
Type: compute.EncryptionTypeEncryptionAtRestWithCustomerKey, | ||||||
Type: compute.EncryptionType(*encryptionType), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here:
Suggested change
|
||||||
DiskEncryptionSetID: utils.String(diskEncryptionSetId), | ||||||
}, | ||||||
}, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -107,6 +107,8 @@ 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`. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been using
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||||||||||
|
||||||||||
* `identity` - (Required) An `identity` block as defined below. | ||||||||||
|
||||||||||
* `tags` - (Optional) A mapping of tags to assign to the Disk Encryption Set. | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -97,6 +97,8 @@ 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) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this fields configured on the Disk Encryption Set rather than the VM, so this comment isn't really necessary:
Suggested change
|
||||
|
||||
* `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. | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.