Assumption
Azure Resource Model.
Steps
There will be several steps to this process. You'll firstly need to retrieve a platform image.
data "azurerm_platform_image" "test" {
location = "West Europe"
publisher = "Microsoft"
offer = "xx"
sku = "xx"
}
Before you can fully populate this however, you will need to retrieve the SKU
and Offer
. Annoyingly, this isn't readily available on the internet and requires an API call or Powershell fun.
This link will help you achieve this.
Once you've got the above terraform populated, you can then utilise this to create a virtual machine.
resource "azurerm_virtual_machine" "test" {
name = "acctvm"
location = "West US 2"
resource_group_name = "${azurerm_resource_group.test.name}"
network_interface_ids = ["${azurerm_network_interface.test.id}"]
vm_size = "Standard_DS1_v2"
storage_image_reference {
id = "${data.azurerm_platform_image.test.id}"
}
storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
# Optional data disks
storage_data_disk {
name = "datadisk_new"
managed_disk_type = "Standard_LRS"
create_option = "Empty"
lun = 0
disk_size_gb = "1023"
}
storage_data_disk {
name = "${azurerm_managed_disk.test.name}"
managed_disk_id = "${azurerm_managed_disk.test.id}"
create_option = "Attach"
lun = 1
disk_size_gb = "${azurerm_managed_disk.test.disk_size_gb}"
}
os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}
os_profile_linux_config {
disable_password_authentication = false
}
tags {
environment = "staging"
}
}