From 189508ec29bd42ddf0b0153746da9f2706a668e9 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 14 Jan 2020 11:05:56 +0100 Subject: [PATCH] r/managed_disk: ensuring that `disk_encryption_set_id` is always set --- .../internal/services/compute/resource_arm_managed_disk.go | 6 ++++-- .../compute/tests/resource_arm_managed_disk_test.go | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/azurerm/internal/services/compute/resource_arm_managed_disk.go b/azurerm/internal/services/compute/resource_arm_managed_disk.go index 999894a4a19f..ae6b32e3198e 100644 --- a/azurerm/internal/services/compute/resource_arm_managed_disk.go +++ b/azurerm/internal/services/compute/resource_arm_managed_disk.go @@ -342,9 +342,11 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error d.Set("disk_mbps_read_write", props.DiskMBpsReadWrite) d.Set("os_type", props.OsType) - if encryption := props.Encryption; encryption != nil { - d.Set("disk_encryption_set_id", encryption.DiskEncryptionSetID) + diskEncryptionSetId := "" + if props.Encryption != nil && props.Encryption.DiskEncryptionSetID != nil { + diskEncryptionSetId = *props.Encryption.DiskEncryptionSetID } + d.Set("disk_encryption_set_id", diskEncryptionSetId) if err := d.Set("encryption_settings", flattenManagedDiskEncryptionSettings(props.EncryptionSettingsCollection)); err != nil { return fmt.Errorf("Error setting `encryption_settings`: %+v", err) diff --git a/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go b/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go index 1a16e15c89b3..9fdce4a44302 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go @@ -219,13 +219,13 @@ func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDiskNonStandardCasing(data), + Config: testAccAzureRMManagedDisk_nonStandardCasing(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, { - Config: testAccAzureRMManagedDiskNonStandardCasing(data), + Config: testAccAzureRMManagedDisk_nonStandardCasing(data), PlanOnly: true, ExpectNonEmptyPlan: false, }, @@ -616,7 +616,7 @@ resource "azurerm_managed_disk" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDiskNonStandardCasing(data acceptance.TestData) string { +func testAccAzureRMManagedDisk_nonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d"