Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update azurerm_managed_disk.disk_encryption_set_id without recreating the resource #6207

Merged
merged 3 commits into from
Mar 23, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions azurerm/internal/services/compute/resource_arm_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ func resourceArmManagedDisk() *schema.Resource {
"disk_encryption_set_id": {
Type: schema.TypeString,
Optional: true,
// Support for rotating the Disk Encryption Set is (apparently) coming a few months following GA
// Code="PropertyChangeNotAllowed" Message="Changing property 'encryption.diskEncryptionSetId' is not allowed."
ForceNew: true,
// 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,
Expand Down Expand Up @@ -364,6 +361,17 @@ func resourceArmManagedDiskUpdate(d *schema.ResourceData, meta interface{}) erro
}
}

if d.HasChange("disk_encryption_set_id") {
if diskEncryptionSetId := d.Get("disk_encryption_set_id").(string); diskEncryptionSetId != "" {
diskUpdate.Encryption = &compute.Encryption{
Type: compute.EncryptionAtRestWithCustomerKey,
DiskEncryptionSetID: utils.String(diskEncryptionSetId),
}
} else {
return fmt.Errorf("Once a customer-managed key is used, you can’t change the selection back to a platform-managed key")
}
}

// if we are attached to a VM we bring down the VM as necessary for the operations which are not allowed while it's online
if disk.ManagedBy != nil {
virtualMachine, err := ParseVirtualMachineID(*disk.ManagedBy)
Expand Down