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

data azurerm_images - support and fix issue with disk_encryption_set_id #22690

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
85 changes: 83 additions & 2 deletions internal/services/compute/images_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func dataSourceImages() *pluginsdk.Resource {
Type: pluginsdk.TypeInt,
Computed: true,
},

"disk_encryption_set_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -215,8 +220,8 @@ func flattenImage(input images.Image) map[string]interface{} {
osDisk := make([]interface{}, 0)
dataDisks := make([]interface{}, 0)
if props := input.Properties; props != nil {
osDisk = flattenImageOSDisk(props.StorageProfile)
dataDisks = flattenImageDataDisks(props.StorageProfile)
osDisk = flattenImagesOSDisk(props.StorageProfile)
dataDisks = flattenImagesDataDisks(props.StorageProfile)

if props.StorageProfile != nil && props.StorageProfile.ZoneResilient != nil {
zoneResilient = *props.StorageProfile.ZoneResilient
Expand All @@ -232,3 +237,79 @@ func flattenImage(input images.Image) map[string]interface{} {
"zone_resilient": zoneResilient,
}
}

func flattenImagesOSDisk(input *images.ImageStorageProfile) []interface{} {
output := make([]interface{}, 0)

if input != nil {
if v := input.OsDisk; v != nil {
blobUri := ""
if uri := v.BlobUri; uri != nil {
blobUri = *uri
}
caching := ""
if v.Caching != nil {
caching = string(*v.Caching)
}
diskSizeGB := 0
if v.DiskSizeGB != nil {
diskSizeGB = int(*v.DiskSizeGB)
}
managedDiskId := ""
if disk := v.ManagedDisk; disk != nil && disk.Id != nil {
managedDiskId = *disk.Id
}
diskEncryptionSetId := ""
if set := v.DiskEncryptionSet; set != nil && set.Id != nil {
diskEncryptionSetId = *set.Id
}
output = append(output, map[string]interface{}{
"blob_uri": blobUri,
"caching": caching,
"managed_disk_id": managedDiskId,
"os_type": string(v.OsType),
"os_state": string(v.OsState),
"size_gb": diskSizeGB,
"disk_encryption_set_id": diskEncryptionSetId,
})
}
}

return output
}

func flattenImagesDataDisks(input *images.ImageStorageProfile) []interface{} {
output := make([]interface{}, 0)

if input != nil {
if v := input.DataDisks; v != nil {
for _, disk := range *input.DataDisks {
blobUri := ""
if disk.BlobUri != nil {
blobUri = *disk.BlobUri
}
caching := ""
if disk.Caching != nil {
caching = string(*disk.Caching)
}
diskSizeGb := 0
if disk.DiskSizeGB != nil {
diskSizeGb = int(*disk.DiskSizeGB)
}
managedDiskId := ""
if disk.ManagedDisk != nil && disk.ManagedDisk.Id != nil {
managedDiskId = *disk.ManagedDisk.Id
}
output = append(output, map[string]interface{}{
"blob_uri": blobUri,
"caching": caching,
"lun": int(disk.Lun),
"managed_disk_id": managedDiskId,
"size_gb": diskSizeGb,
})
}
}
}

return output
}
2 changes: 2 additions & 0 deletions website/docs/d/images.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ The `os_disk` block exports the following:

* `size_gb` - the size of the OS Disk in GB.

* `disk_encryption_set_id` - the ID of the Disk Encryption Set used to encrypt this image.

---

The `data_disk` block exports the following:
Expand Down