From c2af24bfb0ddf13a311126b44eb44002be6ae46a Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 5 Aug 2024 10:00:31 -0500 Subject: [PATCH 01/12] rename property, update docs --- website/docs/r/image.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/image.html.markdown b/website/docs/r/image.html.markdown index 13d4072ddd22..e2187c88cbfa 100644 --- a/website/docs/r/image.html.markdown +++ b/website/docs/r/image.html.markdown @@ -55,6 +55,7 @@ The `os_disk` block supports the following: * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. The default is `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. Changing this forces a new resource to be created. * `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this image. Changing this forces a new resource to be created. +* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values --- @@ -65,6 +66,7 @@ The `data_disk` block supports the following: * `blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image. * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. Defaults to `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. The target size can't be smaller than the source size. +* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values ## Attributes Reference From 7cc5a4daa2e53c2aa81a70ec69d6c32e8da7426f Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 5 Aug 2024 10:31:55 -0500 Subject: [PATCH 02/12] grammar --- website/docs/r/image.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/image.html.markdown b/website/docs/r/image.html.markdown index e2187c88cbfa..1af4b1da16ba 100644 --- a/website/docs/r/image.html.markdown +++ b/website/docs/r/image.html.markdown @@ -55,7 +55,7 @@ The `os_disk` block supports the following: * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. The default is `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. Changing this forces a new resource to be created. * `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this image. Changing this forces a new resource to be created. -* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values +* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values. --- @@ -66,7 +66,7 @@ The `data_disk` block supports the following: * `blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image. * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. Defaults to `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. The target size can't be smaller than the source size. -* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values +* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values. ## Attributes Reference From eac6980a34a65b15bb244c05e4b76514c516c72d Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 5 Aug 2024 10:52:39 -0500 Subject: [PATCH 03/12] add description to properties --- internal/services/compute/image_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 849e1195423e..a2e0182a5447 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -175,6 +175,7 @@ func resourceImage() *pluginsdk.Resource { "blob_uri": { Type: pluginsdk.TypeString, + Description: "The type of storage disk", Optional: true, Computed: true, ValidateFunc: validation.IsURLWithScheme([]string{"http", "https"}), From 7ecc83cf8a582e13b2877545f0de77f053150eb1 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 5 Aug 2024 11:14:20 -0500 Subject: [PATCH 04/12] move description to correct property --- internal/services/compute/image_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index a2e0182a5447..849e1195423e 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -175,7 +175,6 @@ func resourceImage() *pluginsdk.Resource { "blob_uri": { Type: pluginsdk.TypeString, - Description: "The type of storage disk", Optional: true, Computed: true, ValidateFunc: validation.IsURLWithScheme([]string{"http", "https"}), From 646b637d1f6d20e2230924c17985cde57366dde4 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 7 Aug 2024 09:17:36 -0500 Subject: [PATCH 05/12] Update website/docs/r/image.html.markdown Co-authored-by: Tom Bamford --- website/docs/r/image.html.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/website/docs/r/image.html.markdown b/website/docs/r/image.html.markdown index 1af4b1da16ba..4c221591df99 100644 --- a/website/docs/r/image.html.markdown +++ b/website/docs/r/image.html.markdown @@ -55,7 +55,6 @@ The `os_disk` block supports the following: * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. The default is `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. Changing this forces a new resource to be created. * `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this image. Changing this forces a new resource to be created. -* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values. --- From 53c18a89fc68f9e20df17f19ce783de51161e291 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 7 Aug 2024 09:17:46 -0500 Subject: [PATCH 06/12] Update website/docs/r/image.html.markdown Co-authored-by: Tom Bamford --- website/docs/r/image.html.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/website/docs/r/image.html.markdown b/website/docs/r/image.html.markdown index 4c221591df99..13d4072ddd22 100644 --- a/website/docs/r/image.html.markdown +++ b/website/docs/r/image.html.markdown @@ -65,7 +65,6 @@ The `data_disk` block supports the following: * `blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image. * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. Defaults to `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. The target size can't be smaller than the source size. -* `storage_type` - (Optional) The type of storage disk to use. See [Azure API Docs](https://learn.microsoft.com/en-us/rest/api/compute/images/create-or-update?view=rest-compute-2024-03-02&tabs=HTTP#storageaccounttypes) for valid values. ## Attributes Reference From f8371cccb396ea2c6e82b80676eaea984321019c Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 12 Aug 2024 16:21:21 -0500 Subject: [PATCH 07/12] add disk encryption prop to data disk --- internal/services/compute/image_resource.go | 28 +++++++++++++++---- .../services/compute/image_resource_test.go | 23 +++++++++++++-- website/docs/r/image.html.markdown | 3 +- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 849e1195423e..17b3af4a3f6b 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -198,6 +198,13 @@ func resourceImage() *pluginsdk.Resource { ValidateFunc: validation.NoZeroValues, }, + "disk_encryption_set_id": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validate.DiskEncryptionSetID, + }, + "storage_type": { Type: pluginsdk.TypeString, Description: "The type of storage disk", @@ -430,6 +437,12 @@ func expandImageDataDisks(disks []interface{}) *[]images.ImageDataDisk { item.ManagedDisk = managedDisk } + if id := config["disk_encryption_set_id"].(string); id != "" { + item.DiskEncryptionSet = &images.SubResource{ + Id: utils.String(id), + } + } + if features.FourPointOhBeta() { item.StorageAccountType = pointer.To(images.StorageAccountTypes(config["storage_type"].(string))) } @@ -513,13 +526,18 @@ func flattenImageDataDisks(input *images.ImageStorageProfile) []interface{} { if disk.ManagedDisk != nil && disk.ManagedDisk.Id != nil { managedDiskId = *disk.ManagedDisk.Id } + diskEncryptionSetId := "" + if set := disk.DiskEncryptionSet; set != nil && set.Id != nil { + diskEncryptionSetId = *set.Id + } properties := map[string]interface{}{ - "blob_uri": blobUri, - "caching": caching, - "lun": int(disk.Lun), - "managed_disk_id": managedDiskId, - "size_gb": diskSizeGb, + "blob_uri": blobUri, + "caching": caching, + "lun": int(disk.Lun), + "managed_disk_id": managedDiskId, + "size_gb": diskSizeGb, + "disk_encryption_set_id": diskEncryptionSetId, } if features.FourPointOhBeta() { diff --git a/internal/services/compute/image_resource_test.go b/internal/services/compute/image_resource_test.go index e51f917ca911..a9c647f4673b 100644 --- a/internal/services/compute/image_resource_test.go +++ b/internal/services/compute/image_resource_test.go @@ -859,6 +859,24 @@ func (r ImageResource) standaloneImageEncrypt(data acceptance.TestData) string { }` } + dataDisk := ` + data_disk { + blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" + size_gb = 30 + caching = "None" + disk_encryption_set_id = azurerm_disk_encryption_set.test.id + storage_type = "StandardSSD_LRS" + }` + if !features.FourPointOhBeta() { + dataDisk = ` + data_disk { + blob_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" + size_gb = 30 + caching = "None" + disk_encryption_set_id = azurerm_disk_encryption_set.test.id + }` + } + return fmt.Sprintf(` %[1]s @@ -872,7 +890,6 @@ resource "azurerm_key_vault" "test" { sku_name = "standard" purge_protection_enabled = true enabled_for_disk_encryption = true - } resource "azurerm_key_vault_access_policy" "service-principal" { @@ -952,12 +969,14 @@ resource "azurerm_image" "test" { %[4]s + %[5]s + tags = { environment = "Dev" cost-center = "Ops" } } -`, template, data.RandomInteger, data.RandomString, osDisk) +`, template, data.RandomInteger, data.RandomString, osDisk, dataDisk) } func (ImageResource) template(data acceptance.TestData) string { diff --git a/website/docs/r/image.html.markdown b/website/docs/r/image.html.markdown index 13d4072ddd22..16da699c5992 100644 --- a/website/docs/r/image.html.markdown +++ b/website/docs/r/image.html.markdown @@ -54,7 +54,7 @@ The `os_disk` block supports the following: * `blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image. Changing this forces a new resource to be created. * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. The default is `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. Changing this forces a new resource to be created. -* `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this image. Changing this forces a new resource to be created. +* `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this disk. Changing this forces a new resource to be created. --- @@ -65,6 +65,7 @@ The `data_disk` block supports the following: * `blob_uri` - (Optional) Specifies the URI in Azure storage of the blob that you want to use to create the image. * `caching` - (Optional) Specifies the caching mode as `ReadWrite`, `ReadOnly`, or `None`. Defaults to `None`. * `size_gb` - (Optional) Specifies the size of the image to be created. The target size can't be smaller than the source size. +* `disk_encryption_set_id` - (Optional) The ID of the Disk Encryption Set which should be used to encrypt this disk. Changing this forces a new resource to be created. ## Attributes Reference From f6dffc7f76e5434396ab77b1bf4aea06a84438d5 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Fri, 16 Aug 2024 09:16:32 -0500 Subject: [PATCH 08/12] Update internal/services/compute/image_resource.go Co-authored-by: stephybun --- internal/services/compute/image_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 17b3af4a3f6b..11e5620b7df7 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -439,7 +439,7 @@ func expandImageDataDisks(disks []interface{}) *[]images.ImageDataDisk { if id := config["disk_encryption_set_id"].(string); id != "" { item.DiskEncryptionSet = &images.SubResource{ - Id: utils.String(id), + Id: pointer.To(id), } } From ae62cbbcdd973721a4ce312ef9c8658a8b085059 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Fri, 16 Aug 2024 09:28:09 -0500 Subject: [PATCH 09/12] parse returned ids --- internal/services/compute/image_resource.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 11e5620b7df7..04a572bbde59 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -398,8 +398,9 @@ func expandImageOSDisk(input []interface{}) *images.ImageOSDisk { } if id := config["disk_encryption_set_id"].(string); id != "" { + encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(id) out.DiskEncryptionSet = &images.SubResource{ - Id: utils.String(id), + Id: pointer.To(encryptionId.String()), } } @@ -438,8 +439,9 @@ func expandImageDataDisks(disks []interface{}) *[]images.ImageDataDisk { } if id := config["disk_encryption_set_id"].(string); id != "" { + encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(id) item.DiskEncryptionSet = &images.SubResource{ - Id: pointer.To(id), + Id: pointer.To(encryptionId.String()), } } From 4f9e116f61c89168dfa64696e686dc4d237e665b Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Fri, 16 Aug 2024 09:32:08 -0500 Subject: [PATCH 10/12] parse response, not request :P --- internal/services/compute/image_resource.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 04a572bbde59..aacb3c6d7dd9 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -398,9 +398,8 @@ func expandImageOSDisk(input []interface{}) *images.ImageOSDisk { } if id := config["disk_encryption_set_id"].(string); id != "" { - encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(id) out.DiskEncryptionSet = &images.SubResource{ - Id: pointer.To(encryptionId.String()), + Id: pointer.To(id), } } @@ -439,9 +438,8 @@ func expandImageDataDisks(disks []interface{}) *[]images.ImageDataDisk { } if id := config["disk_encryption_set_id"].(string); id != "" { - encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(id) item.DiskEncryptionSet = &images.SubResource{ - Id: pointer.To(encryptionId.String()), + Id: pointer.To(id), } } @@ -478,7 +476,8 @@ func flattenImageOSDisk(input *images.ImageStorageProfile) []interface{} { } diskEncryptionSetId := "" if set := v.DiskEncryptionSet; set != nil && set.Id != nil { - diskEncryptionSetId = *set.Id + encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(*set.Id) + diskEncryptionSetId = encryptionId.String() } properties := map[string]interface{}{ @@ -530,7 +529,8 @@ func flattenImageDataDisks(input *images.ImageStorageProfile) []interface{} { } diskEncryptionSetId := "" if set := disk.DiskEncryptionSet; set != nil && set.Id != nil { - diskEncryptionSetId = *set.Id + encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(*set.Id) + diskEncryptionSetId = encryptionId.String() } properties := map[string]interface{}{ From c2037ea79c97aba8f605a39bdd1fe07878b3a21d Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 19 Aug 2024 08:51:41 -0500 Subject: [PATCH 11/12] Update internal/services/compute/image_resource.go Co-authored-by: stephybun --- internal/services/compute/image_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index aacb3c6d7dd9..63f254cff16c 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -477,7 +477,7 @@ func flattenImageOSDisk(input *images.ImageStorageProfile) []interface{} { diskEncryptionSetId := "" if set := v.DiskEncryptionSet; set != nil && set.Id != nil { encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(*set.Id) - diskEncryptionSetId = encryptionId.String() + diskEncryptionSetId = encryptionId.ID() } properties := map[string]interface{}{ From f49fe095ca060a271688c5809e3617502618e18b Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Mon, 19 Aug 2024 08:51:46 -0500 Subject: [PATCH 12/12] Update internal/services/compute/image_resource.go Co-authored-by: stephybun --- internal/services/compute/image_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/compute/image_resource.go b/internal/services/compute/image_resource.go index 63f254cff16c..dd65c7cac171 100644 --- a/internal/services/compute/image_resource.go +++ b/internal/services/compute/image_resource.go @@ -530,7 +530,7 @@ func flattenImageDataDisks(input *images.ImageStorageProfile) []interface{} { diskEncryptionSetId := "" if set := disk.DiskEncryptionSet; set != nil && set.Id != nil { encryptionId, _ := commonids.ParseDiskEncryptionSetIDInsensitively(*set.Id) - diskEncryptionSetId = encryptionId.String() + diskEncryptionSetId = encryptionId.ID() } properties := map[string]interface{}{