Virtual Machine

Overview

The Virtual Machine builder creates a fully configured virtual machine and all its required child resources.

  • Virtual Machines (Microsoft.Compute/virtualMachines)
  • Virtual Networks (Microsoft.Network/virtualNetworks)
  • IP Addresses (Microsoft.Network/publicIPAddresses)
  • Network Interfaces (Microsoft.Network/networkInterfaces)
  • Storage Accounts (Microsoft.Storage/storageAccounts)

In addition, every VM you create will add a SecureString parameter to the ARM template, whose name follows the pattern password-for-[virtual machine name].

Builder Keywords

KeywordPurpose
nameSets the name of the VM.
diagnostics_supportTurns on diagnostics support using an automatically created storage account.
diagnostics_support_managedTurns on diagnostics support using an Azure-managed storage account.
diagnostics_support_externalTurns on diagnostics support using an existing storage account.
vm_sizeSets the size of the VM.
prioritySets the VM Priority. Only one spot_instance or priority setting is allowed per VM. No priority is set by default.
spot_instanceMakes the VM a spot instance. Shorthand for priority (Spot (<EvictionPolicy>, <maxPrice>). Only one spot_instance or priority setting is allowed per VM.
usernameSets the admin username of the VM (note: the password is supplied as a securestring parameter to the generated ARM template).
password_parameterSets the name of the parameter which contains the admin password for this VM. defaults to “password-for-”
add_availability_zoneSets the availability zone for the VM.
operating_systemSets the operating system of the VM. A set of samples is provided in the CommonImages module.
os_diskSets the size and type of the OS disk for the VM. Note: The default is non-SSD.
add_diskAdds a data disk to the VM with a specific size and type.
add_ssd_diskAdds a SSD data disk to the VM with a specific size.
add_slow_diskAdds a conventional (non-SSD) data disk to the VM with a specific size.
attach_os_diskAttaches an newly imported managed disk to the VM as the OS disk. The OS (Windows or Linux) for the image must be specified. When attaching an OS disk, the OS settings such as username, password, and configData cannot be set.
attach_existing_os_diskAttaches an existing managed disk to the VM as the OS disk.
attach_data_diskAttaches an newly imported managed disk to the VM as a data disk.
attach_existing_data_diskAttaches an existing managed disk to the VM as a data disk.
no_data_diskExcludes a data disk (only an OS disk) - common when mounting cloud storage.
domain_name_prefixSets the prefix for the domain name of the VM.
address_prefixSets the IP address prefix of the VM.
subnet_prefixSets the subnet prefix of the VM.
custom_scriptExecutes the supplied inline custom script on the VM. Supports only one command. Alternatively you can connect VM e.g. with Powershell Invoke-AzVMRunCommand.
custom_script_filesUploads the supplied set of files, specified by URI, to the VM on creation.
aad_ssh_loginAdds the AADSSHLoginForLinux extension on Linux VM’s (requires system_identity).
custom_dataSets the custom data field for the VM.
disable_password_authenticationDisables password authentication on the VM. Must include at least one key if true
add_application_security_groupsAssign this VM to one or more application security groups
add_authorized_keyadds one authorized key
add_authorized_keysadds a list of authorized keys
add_gallery_applicationsAdds one or more gallery applications to this VM.
add_gallery_applications_install_orderAdds one or more gallery applications and sets the install order in the order they are added.
add_identityAdds a managed identity to the Virtual Machine.
system_identityActivates the system identity of the Virtual Machine.
public_ipSpecifies or removes the public IP for this VM
ip_allocationSets the public IP as Dynamic or Static. Default is dynamic.
private_ip_allocationSets the private IP as Dynamic or Static. Default is dynamic.
ip_forwardingEnable or disable IP forwarding on the primary network interface. Secondary NICs will leave it undefined.
accelerated_networkingEnable or disable accelerated networking on all network interfaces generated for the VM.
add_ip_configurationAdd ipConfig definitions to add additional IP addresses or connect to multiple subnets. Connecting to additional subnets will generate a NIC for each subnet.
network_security_groupSets the Network Security Group (NSG) for VM/NIC. Enables you to create and share firewall rule sets.
link_to_network_security_groupSpecify an existing Network Security Group (NSG) for VM/NIC.
link_application_security_groupsLink this VM to one or more application security groups (no dependency generated).
link_to_vnetAttaches the VM NIC to a vnet that is deployed in this same template
link_to_unmanaged_vnetAttaches the VM NIC to a vnet that is already deployed
link_to_backend_address_poolAdds the VM network interface to a load balancer backend address pool that is deployed with this VM.
link_to_unmanaged_backend_address_poolAdds the VM network interface to an existing load balancer backend address pool.

The vmGalleryApplicationBuilder is used to add a gallery application to a VM.

KeywordPurpose
enable_automatic_upgradeOptional. Enables automatic upgrade of the application when a new version is released.
orderOptional. The order in which applications should be installed.
package_reference_idRequired. References an existing gallery application version to install on the VM.
tagsOptional. Specifies a passthrough value for more generic context.
treat_failure_as_deployment_failureOptional. If true, any failure for any operation in the VmApplication will fail the deployment

Configuration Members

MemberPurpose
NicNameProvides the resource name of the Network Interface Card (NIC)
VnetNameProvides the resource name of the Virtual Network (VNet)
SubnetNameProvides the resource name of the subnet
IpNameProvides the resource name of the IP Address
PublicIpAddressReturns an ARM expression to retrieve public IP address of the virtual machine.
HostnameReturns an ARM expression to retrieve the fully-qualified domain name from the virtual machine’s DNS settings.”

Example

open Farmer
open Farmer.Builders

let myVm = vm {
    name "myFarmerVm"
    username "yourUsername"
    vm_size Vm.Standard_A2
    operating_system Vm.WindowsServer_2012Datacenter
    os_disk 128 Vm.StandardSSD_LRS
    add_ssd_disk 128
    add_slow_disk 512
    custom_script "powershell setup-vm.ps1" // you have to actually *call* the script
    custom_script_files [ "https://foo.bar/foo/setup-vm.ps1" ]
    custom_data "customData"
    disable_password_authentication true
    add_authorized_key "fooPath" "fooKey"
    add_authorized_keys [("fooPath", "fooKey");("fooPath1", "fooKey1")]
    private_ip_allocation (PrivateIpAddress.StaticPrivateIp (Net.IPAddress.Parse("10.0.0.10")))
}