Open jpbuecken opened 3 years ago
Yes please, additional vote here!
Workaround:
data "azapi_resource" "example-reference-name" {
name = "name-of-your-vm"
parent_id = azurerm_resource_group.reference-name-of-your-resource-group.id
type = "Microsoft.Compute/virtualMachines@2024-07-01"
response_export_values = ["properties.storageProfile.osDisk.managedDisk.id"]
}
# Use the below to pass the ID to other resources. e.g,
resource "example" "examplename" {
...
disk_id = jsondecode(data.azapi_resource.example-reference-name.output).properties.storageProfile.osDisk.managedDisk.id
...
}
Community Note
Description
After creating a VM it would be nice to access the os_disk id in terraform code.
In my use case I want to give the VM the READER role to read information about its os_disk. (for example, this is needed for the new Azure Enhanced Monitoring for SAP extension [1], [2])
Possible idea: Call the managed disk datasource code internally after instance has been created to fill values for os_disk?
New or Affected Resource(s)
Potential Terraform Configuration
You need to rollout the VM first before you can add the code for role assignment, otherwise principal id is not available. Maybe this can be fixed with this Issue as well?
References
[1] https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/deployment-guide#d98edcd3-f2a1-49f7-b26a-07448ceb60ca [2] https://github.com/Azure/azure-cli-extensions/issues/3019#issuecomment-785022356