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

[Enhancement] azurerm_image add disk_encryption_set_id to data_disk #27015

Merged
28 changes: 23 additions & 5 deletions internal/services/compute/image_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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),
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved
}
}

if features.FourPointOhBeta() {
item.StorageAccountType = pointer.To(images.StorageAccountTypes(config["storage_type"].(string)))
}
Expand Down Expand Up @@ -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
bruceharrison1984 marked this conversation as resolved.
Show resolved Hide resolved
}

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() {
Expand Down
23 changes: 21 additions & 2 deletions internal/services/compute/image_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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" {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/image.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand All @@ -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

Expand Down
Loading