Virtual Machine Scale Set

Overview

The Virtual Machine Scale Set builder (vmss) creates a virtual machine scale set that can grow and shrink it’s capacity by creating virtual machines and their dependent resources from a common profile.

  • Virtual Machine Scale Sets (Microsoft.Compute/virtualMachineScaleSets)

Builder Keywords

BuilderKeywordPurpose
vmssnameSets the name of the VM scale set.
vmssvm_profileDefines a profile for VM’s in the scale set using the vm builder to support all the same functionality as a single VM.
vmssadd_availability_zonesAdds one or more availability zones so VM resources will be distributed across those zones.
vmssadd_extensionsAdds extensions that will be automatically installed on VMs when scaling out.
vmssautomatic_repair_policyEnables automatically replacing VMs in the scale set that report as unhealthy. Requires adding the Application Health Extension.
vmssautomatic_repair_enabled_afterDefines a grace period after becoming unhealthy before replacing the instance.
vmsscapacityThe number of VM instances in the scale set.
vmsshealth_probeIf not using an application health extension, this refers to a load balancer health probe that can indicate instance health.
vmssscale_in_policySpecify the policy for determining which VMs to remove when scaling in.
vmssscale_in_force_deletionIndicates the VMs should be force deleted so they free the resources more quickly.
vmssupgrade_modeSpecify Manual, Automatic, or Rolling upgrades. Rolling upgrades require the Application Health Extension or a Health Probe to ensure newly replaced instances are healthy before replacing more of them.
applicationHealthExtensionvmssWhen adding the extension as a resource, this specifies the VM scale set it should be applied to.
applicationHealthExtensionosOperating system (Linux or Windows) to install the correct extension for that OS.
applicationHealthExtensionprotocolProtocol (TCP, HTTP, or HTTPS) to probe, and if specifying HTTP or HTTPS, include the path.
applicationHealthExtensionportTCP port to probe.
applicationHealthExtensionintervalInterval to probe for health.
applicationHealthExtensionnumber_of_probesSets the number times the probe must fail to consider this instance a failure.

Example

This example creates a scale set with 3 VM instances and includes the Application Health Extension to support rolling updates and automatic repairs.

open Farmer
open Farmer.Builders
open Farmer.Vm
open Farmer.VmScaleSet

vmss {
    name "my-scale-set"
    capacity 3

    vm_profile (
        vm {
            username "azureuser"
            operating_system UbuntuServer_2204LTS
            vm_size Standard_B1s
            os_disk 128 StandardSSD_LRS
            diagnostics_support_managed
            custom_script "sudo apt update && sudo apt install -y nginx"
        }
    )
    scale_in_policy OldestVM
    upgrade_mode Rolling
    automatic_repair_enabled_after (System.TimeSpan.FromMinutes 10)
    add_extensions [
        applicationHealthExtension {
            protocol (ApplicationHealthExtensionProtocol.HTTP "/healthcheck")
            port 80
            os Linux
        }
    ]

}