Open kaiyanqiu opened 1 year ago
@kaiyanqiu thanks for opening the issue! Unfortunately currently due to design trade-off in resources azurerm_linux_virtual_machine
and azurerm_windows_virtual_machine
we are not able to simply mark the os_profile
as Optional
according to what has been discussed in #7524. And similar to #8195, when using an existing OS Disk to create the VM resource, os_profile
can also not be provided and not returned from the API. While this needs more consideration for how to properly implement these features in the current structure, while we are making further decision of how to implement this, I'd suggest using a Generalized image as a workaround.
In the meantime, I suggest a line in the doco for azurerm_linux_virtual_machine
that specialized VM images are not supported yet. Took me much too long to find this Issue based on a rather obscure error message.
+1 for azurerm_windows_virtual_machine
(to add documentation stating that a Specialised image is NOT supported). A lot of time is wasted trying to understand what this error means, as the parameter/block is not explicitly referenced as part of these resources.
Is there an existing issue for this?
Community Note
Terraform Version
1.0.2
AzureRM Provider Version
3.69.0
Affected Resource(s)/Data Source(s)
azurerm_linux_virtual_machine
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
From the resource: azurerm_virtual_machine is able to provision generalized shared gallery image successfully, but for resource: azurerm_linux_virtual_machine is unable to provision generalized shared gallery image. According to GitHub: https://github.com/hashicorp/terraform-provider-azurerm/issues/7772, would like to confirm whether this is a product limitation, if so, will it have a fix roll out in the future.
Actual Behaviour
For resource: azurerm_linux_virtual_machine is unable to provision generalized shared gallery image.
Steps to Reproduce
terraform { required_providers { azurerm = { source = "hashicorp/azurerm" version = "~> 3.69.0" } }
required_version = ">= 1.0.0" }
provider "azurerm" { features {} }
data "azurerm_shared_image" "example" { name = "Specializednew" gallery_name = "test0810" resource_group_name = "Linux" }
resource "azurerm_virtual_machine" "example2"{
}
resource "azurerm_virtual_machine" "example1" { name = "testspecialized" resource_group_name = "Linux" location = "East US" vm_size = "Standard_D4s_v3"
admin_username = "azuretest"
admin_password = "xxxxxxx"
network_interface_ids = [ "/subscriptions/xxxxxxxx/resourceGroups/Linux/providers/Microsoft.Network/networkInterfaces/azuetest907" ]
source_image_id = data.azurerm_shared_image.example.id
storage_image_reference { id = data.azurerm_shared_image.example.id } storage_os_disk { name = "myosdisk1" caching = "ReadWrite" create_option = "FromImage" managed_disk_type = "Standard_LRS" }
admin_username = "azureuser" #"azureuser"
disable_password_authentication = false
computer_name = "xxxxxx002" #"vmnvi-terraform"
os_disk {
name = "testosdisk"
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
source_image_id = "/subscriptions/xxxxxx/resourceGroups/rg-nvi-cmp-dev-infra/providers/Microsoft.Compute/galleries/NewGallery1.1/images/Definition1.1/versions/1.1.0" # data.azurerm_shared_image.example.id
source_image_reference { #source
publisher = "almalinux"
offer = "almalinux"
sku = "9-gen2"
version = "latest"
}
plan {
name = "9-gen2"
publisher = "almalinux"
product = "almalinux"
}
admin_ssh_key {
username = "azureuser"
public_key = var.public-key
}
boot_diagnostics {
storage_account_uri = var.storage-account-uri
}
lifecycle {
prevent_destroy = false
ignore_changes = [
tags["CreatedDate"],
tags["CreatedBy"]
]
}
tags = merge(
tomap({
Notes=var.tag_vm_notes
}),
var.default_tags
)
}
}
Important Factoids
No response
References
https://github.com/hashicorp/terraform-provider-azurerm/issues/7772 From VM documentation, Computer names of specialized virtual machines are missing or blank in Azure - Virtual Machines | Microsoft Learn, when creating virtual machine with specialized image, the request cannot include 'OsProfile'.