The following arguments are supported:
Note:
This setting works when instance is deleted via Terraform only and don't forget to delete disks manually if you deleted VM manually. It can increase spending.
Note:
This setting works when instance is deleted via Terraform only and don't forget to delete disks manually if you deleted VM manually. It can increase spending.
Please Note:
Data Disks can also be attached either using this block or the azurerm_ virtual_machine_data_disk_attachment resource - but not both.
Please Note:
Availability Zones are only supported in several regions at this time.
For more information on the different example configurations, please check out the Azure documentation
An additional_unattend_config block supports the following:
A boot_diagnostics block supports the following:
NOTE:
This needs to be the root of a Storage Account and not a Storage Container.
A additional_capabilities block supports the following:
Note:
Azure Ultra Disk Storage is only available in a region that support availability zones and can only enabled on the following VM series: ESv3, DSv3, FSv3, LSv2, M and Mv2. For more information see the Azure Ultra Disk Storage product documentation.
A identity block supports the following:
NOTE:
Managed Service Identity previously required the installation of a VM Extension, but this information is now available via the Azure Instance Metadata Service.
NOTE:
When type is set to SystemAssigned, identity the Principal ID can be retrieved after the virtual machine has been created. More details are available below. See documentation for additional information.
NOTE:
This is required when type is set to UserAssigned or SystemAssigned, UserAssigned.
A os_profile block supports the following:
NOTE:
If using Linux, it may be preferable to use SSH Key authentication (available in the os_profile_linux_config block) instead of password authentication.
NOTE:
admin_password must be between 6-72 characters long and must satisfy at least 3 of password complexity requirements from the following:
A os_profile_linux_config block supports the following:
A os_profile_secrets block supports the following:
A os_profile_windows_config block supports the following:
NOTE:
This is different from the Default value used for this field within Azure.
A plan block supports the following:
A ssh_keys block supports the following:
Note:
Azure only supports RSA SSH2 key signatures of at least 2048 bits in length
NOTE:
Rather than defining this in-line you can source this from a local file using the file function - for example key_data = file("~/.ssh/id_rsa.pub").
NOTE:
Due to a limitation in the Azure VM Agent the only allowed path is /home/{username}/.ssh/authorized_keys.
A storage_image_reference block supports the following:
This block provisions the Virtual Machine from one of two sources: an Azure Platform Image (e.g. Ubuntu/Windows Server) or a Custom Image.
To provision from an Azure Platform Image, the following fields are applicable:
To provision a Custom Image, the following fields are applicable:
NOTE:
An example of how to use this is available within the ./examples/virtual-machines/virtual_machine/managed-disks/from-custom-image directory within the GitHub Repository
A storage_data_disk block supports the following:
NOTE:
Data Disks can also be attached either using this block or the azurerm_virtual_machine_data_disk_attachment resource - but not both.
NOTE:
If using an image that does not have data to be written to the Data Disk, use Empty as the create option in order to create the desired disk without any data.
The following properties apply when using Managed Disks:
Note:
managed_disk_type of type UltraSSD_LRS is currently in preview and are not available to subscriptions that have not requested onboarding to Azure Ultra Disk Storage preview. Azure Ultra Disk Storage is only available in East US 2, North Europe, and Southeast Asia regions. For more information see the Azure Ultra Disk Storage product documentation, product blog and FAQ. You must also set additional_capabilities.ultra_ssd_enabled to true.
The following properties apply when using Unmanaged Disks:
A storage_os_disk block supports the following:
The following properties apply when using Managed Disks:
The following properties apply when using Unmanaged Disks:
A vault_certificates block supports the following:
{
"data":"",
"dataType":"pfx",
"password":""
}
NOTE:
If your certificate is stored in Azure Key Vault - this can be sourced from the secret_id property on the azurerm_key_vault_certificate resource.
A winrm block supports the following:
NOTE:
This can be sourced from the secret_id field on the azurerm_key_vault_certificate resource.
variable "prefix" {
default = "tfvmex"
}
resource "azurerm_resource_group" "example" {
name = "${var.prefix}-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "main" {
name = "${var.prefix}-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_configuration {
name = "testconfiguration1"
subnet_id = azurerm_subnet.internal.id
private_ip_address_allocation = "Dynamic"
}
}
resource "azurerm_virtual_machine" "main" {
name = "${var.prefix}-vm"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.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 = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
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
}
tags = {
environment = "staging"
}
}
az vm create --name
--resource-group
[--accelerated-networking {false, true}]
[--accept-term]
[--admin-password]
[--admin-username]
[--asgs]
[--assign-identity]
[--attach-data-disks]
[--attach-os-disk]
[--authentication-type {all, password, ssh}]
[--availability-set]
[--boot-diagnostics-storage]
[--capacity-reservation-group]
[--computer-name]
[--count]
[--custom-data]
[--data-disk-caching]
[--data-disk-delete-option]
[--data-disk-encryption-sets]
[--data-disk-sizes-gb]
[--disable-integrity-monitoring]
[--disk-controller-type {NVMe, SCSI}]
[--edge-zone]
[--enable-agent {false, true}]
[--enable-auto-update {false, true}]
[--enable-hibernation {false, true}]
[--enable-hotpatching {false, true}]
[--enable-secure-boot {false, true}]
[--enable-vtpm {false, true}]
[--encryption-at-host {false, true}]
[--ephemeral-os-disk {false, true}]
[--ephemeral-os-disk-placement {CacheDisk, ResourceDisk}]
[--eviction-policy {Deallocate, Delete}]
[--generate-ssh-keys]
[--host]
[--host-group]
[--image]
[--license-type {None, RHEL_BASE, RHEL_BASESAPAPPS, RHEL_BASESAPHA, RHEL_BYOS, RHEL_ELS_6, RHEL_EUS, RHEL_SAPAPPS, RHEL_SAPHA, SLES, SLES_BYOS, SLES_HPC, SLES_SAP, SLES_STANDARD, Windows_Client, Windows_Server}]
[--location]
[--max-price]
[--nic-delete-option]
[--nics]
[--no-wait]
[--nsg]
[--nsg-rule {NONE, RDP, SSH}]
[--os-disk-caching {None, ReadOnly, ReadWrite}]
[--os-disk-delete-option {Delete, Detach}]
[--os-disk-encryption-set]
[--os-disk-name]
[--os-disk-secure-vm-disk-encryption-set]
[--os-disk-security-encryption-type {DiskWithVMGuestState, VMGuestStateOnly}]
[--os-disk-size-gb]
[--os-type {linux, windows}]
[--patch-mode {AutomaticByOS, AutomaticByPlatform, ImageDefault, Manual}]
[--plan-name]
[--plan-product]
[--plan-promotion-code]
[--plan-publisher]
[--platform-fault-domain]
[--ppg]
[--priority {Low, Regular, Spot}]
[--private-ip-address]
[--public-ip-address]
[--public-ip-address-allocation {dynamic, static}]
[--public-ip-address-dns-name]
[--public-ip-sku {Basic, Standard}]
[--role]
[--scope]
[--secrets]
[--security-type {ConfidentialVM, TrustedLaunch}]
[--size]
[--specialized {false, true}]
[--ssh-dest-key-path]
[--ssh-key-name]
[--ssh-key-values]
[--storage-account]
[--storage-container-name]
[--storage-sku]
[--subnet]
[--subnet-address-prefix]
[--tags]
[--ultra-ssd-enabled {false, true}]
[--use-unmanaged-disk]
[--user-data]
[--v-cpus-available]
[--v-cpus-per-core]
[--validate]
[--vmss]
[--vnet-address-prefix]
[--vnet-name]
[--workspace]
[--zone {1, 2, 3}]
az vm create -n MyVm -g MyResourceGroup --image /SharedGalleries/{gallery_unique_name}/Images/{image}/Versions/{version}
Categorized by Availability, Security & Compliance and Cost