I do not want to hardcode var.windowsimage as I would like the script to be portable for linuximages etc.
Something like this but I’m not unsure of the expression
I do not understand your question but I am happy to help.
What I understand is that your are trying to create a Terraform stack (script) that can create Azure VM with both Linux and Windows operating systems. Never done that myself with Azure but with AWS. In my understanding you can do that easily by calling Terraform with the right set of parameters as input. The example in the documentation (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_machine) has nothing OS specific as far as I understand it.
Is it maybe a deployement problem? What if you had something like that in your stack:
variable "publisher" {
type = string
}
variable "offer" {
type = string
}
variable "sku" {
type = string
}
variable "version" {
type = string
}
resource "azurerm_virtual_machine" "main" {
name = "my-vm"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
network_interface_ids = [azurerm_network_interface.main.id]
vm_size = "Standard_DS1_v2"
# Uncomment this line to delete the OS disk automatically when deleting the VM
# delete_os_disk_on_termination = true
# Uncomment this line to delete the data disks automatically when deleting the VM
# delete_data_disks_on_termination = true
storage_image_reference {
publisher = var.publisher
offer = var.offer
sku = var.sku
version = var.version
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
}
Then when you want to create a VM with Ubuntu 16.04-LTS you invoke Terraform that way:
I want to be able to change variable vmos between “windowsimage” and “linuximage”.
This will then query the variable “windowsimage” and variable “linuximage”
So from my createvm.tf, instead of putting in a hard variable of var.windowsimage, I want to be able to query var.azurevm[vmos] which is windowsimage then append it so my publisher = var.windowsimage[“publisher”] or publisher = var.linuximage[“publisher”] depending on what is entered for vmos