diff --git a/azurerm/resource_arm_virtual_machine_scale_set.go b/azurerm/resource_arm_virtual_machine_scale_set.go index 1da2ae2e3ed0b..b28e09f4d9716 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/azurerm/resource_arm_virtual_machine_scale_set.go @@ -196,6 +196,17 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { }, true), }, + "eviction_policy": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: string(compute.Deallocate), + ValidateFunc: validation.StringInSlice([]string{ + string(compute.Deallocate), + string(compute.Delete), + }, false), + }, + "os_profile": { Type: schema.TypeList, Required: true, @@ -782,6 +793,7 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf overprovision := d.Get("overprovision").(bool) singlePlacementGroup := d.Get("single_placement_group").(bool) priority := d.Get("priority").(string) + evictionPolicy := d.Get("eviction_policy").(string) scaleSetProps := compute.VirtualMachineScaleSetProperties{ UpgradePolicy: &compute.UpgradePolicy{ @@ -800,6 +812,10 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf SinglePlacementGroup: &singlePlacementGroup, } + if strings.EqualFold(priority, string(compute.Low)) { + scaleSetProps.VirtualMachineProfile.EvictionPolicy = compute.VirtualMachineEvictionPolicyTypes(evictionPolicy) + } + if _, ok := d.GetOk("boot_diagnostics"); ok { diagnosticProfile := expandAzureRMVirtualMachineScaleSetsDiagnosticProfile(d) scaleSetProps.VirtualMachineProfile.DiagnosticsProfile = &diagnosticProfile @@ -912,7 +928,8 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac if profile := properties.VirtualMachineProfile; profile != nil { d.Set("license_type", profile.LicenseType) - d.Set("priority", profile.Priority) + d.Set("priority", string(profile.Priority)) + d.Set("eviction_policy", string(profile.EvictionPolicy)) osProfile := flattenAzureRMVirtualMachineScaleSetOsProfile(d, profile.OsProfile) if err := d.Set("os_profile", osProfile); err != nil { diff --git a/azurerm/resource_arm_virtual_machine_scale_set_test.go b/azurerm/resource_arm_virtual_machine_scale_set_test.go index c2f7947744aed..cdd72dc6a997d 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/resource_arm_virtual_machine_scale_set_test.go @@ -28,6 +28,33 @@ func TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) { testCheckAzureRMVirtualMachineScaleSetExists(resourceName), // testing default scaleset values testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(resourceName, true), + resource.TestCheckResourceAttr(resourceName, "eviction_policy", "deallocate"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, + }, + }, + }) +} + +func TestAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(t *testing.T) { + resourceName := "azurerm_virtual_machine_scale_set.test" + ri := acctest.RandInt() + config := testAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "eviction_policy", "delete"), ), }, { @@ -1295,6 +1322,94 @@ resource "azurerm_virtual_machine_scale_set" "test" { `, rInt, location) } +func testAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%[1]d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%[1]d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_storage_account" "test" { + name = "accsa%[1]d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_tier = "Standard" + account_replication_type = "LRS" + + tags { + environment = "staging" + } +} + +resource "azurerm_storage_container" "test" { + name = "vhds" + resource_group_name = "${azurerm_resource_group.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" + container_access_type = "private" +} + +resource "azurerm_virtual_machine_scale_set" "test" { + name = "acctvmss-%[1]d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + upgrade_policy_mode = "Manual" + priority = "Low" + eviction_policy = "Delete" + + sku { + name = "Standard_D1_v2" + tier = "Standard" + capacity = 2 + } + + os_profile { + computer_name_prefix = "testvm-%[1]d" + admin_username = "myadmin" + admin_password = "Passwword1234" + } + + network_profile { + name = "TestNetworkProfile-%[1]d" + primary = true + + ip_configuration { + name = "TestIPConfiguration" + primary = true + subnet_id = "${azurerm_subnet.test.id}" + } + } + + storage_profile_os_disk { + name = "osDiskProfile" + caching = "ReadWrite" + create_option = "FromImage" + vhd_containers = ["${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}"] + } + + storage_profile_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } +} +`, rInt, location) +} + func testAccAzureRMVirtualMachineScaleSet_standardSSD(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { diff --git a/website/docs/r/virtual_machine_scale_set.html.markdown b/website/docs/r/virtual_machine_scale_set.html.markdown index b231661bf74c3..d943ffe163442 100644 --- a/website/docs/r/virtual_machine_scale_set.html.markdown +++ b/website/docs/r/virtual_machine_scale_set.html.markdown @@ -269,24 +269,25 @@ The following arguments are supported: * `sku` - (Required) A sku block as documented below. * `upgrade_policy_mode` - (Required) Specifies the mode of an upgrade to virtual machines in the scale set. Possible values, `Rolling`, `Manual`, or `Automatic`. When choosing `Rolling`, you will need to set a health probe. * `automatic_os_upgrade` - (Optional) Automatic OS patches can be applied by Azure to your scaleset. This is particularly useful when `upgrade_policy_mode` is set to `Rolling`. Defaults to `false`. -* `rolling_upgrade_policy` - (Optional) A `rolling_upgrade_policy` block as defined below. This is only applicable when the `upgrade_policy_mode` is `Rolling`. +* `eviction_policy` - (Optional) Specifies the eviction policy for Virtual Machines in this Scale Set. Defaults to `Deallocate`. Possible values are `Deallocate` and `Delete`. * `health_probe_id` - (Optional) Specifies the identifier for the load balancer health probe. Required when using `Rolling` as your `upgrade_policy_mode`. -* `overprovision` - (Optional) Specifies whether the virtual machine scale set should be overprovisioned. -* `single_placement_group` - (Optional) Specifies whether the scale set is limited to a single placement group with a maximum size of 100 virtual machines. If set to false, managed disks must be used. Default is true. Changing this forces a - new resource to be created. See [documentation](http://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-placement-groups) for more information. * `license_type` - (Optional, when a Windows machine) Specifies the Windows OS license type. If supplied, the only allowed values are `Windows_Client` and `Windows_Server`. * `os_profile` - (Required) A Virtual Machine OS Profile block as documented below. * `os_profile_secrets` - (Optional) A collection of Secret blocks as documented below. * `os_profile_windows_config` - (Required, when a windows machine) A Windows config block as documented below. * `os_profile_linux_config` - (Required, when a linux machine) A Linux config block as documented below. * `network_profile` - (Required) A collection of network profile block as documented below. +* `overprovision` - (Optional) Specifies whether the virtual machine scale set should be overprovisioned. +* `rolling_upgrade_policy` - (Optional) A `rolling_upgrade_policy` block as defined below. This is only applicable when the `upgrade_policy_mode` is `Rolling`. +* `single_placement_group` - (Optional) Specifies whether the scale set is limited to a single placement group with a maximum size of 100 virtual machines. If set to false, managed disks must be used. Default is true. Changing this forces a + new resource to be created. See [documentation](http://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-placement-groups) for more information. * `storage_profile_os_disk` - (Required) A storage profile os disk block as documented below * `storage_profile_data_disk` - (Optional) A storage profile data disk block as documented below * `storage_profile_image_reference` - (Optional) A storage profile image reference block as documented below. * `extension` - (Optional) Can be specified multiple times to add extension profiles to the scale set. Each `extension` block supports the fields documented below. * `boot_diagnostics` - (Optional) A boot diagnostics profile block as referenced below. * `plan` - (Optional) A plan block as documented below. -* `priority` - (Optional) Specifies the priority for the virtual machines in the scale set, defaults to `Regular`. Possible values are `Low` and `Regular`. +* `priority` - (Optional) Specifies the priority for the Virtual Machines in the Scale Set. Defaults to `Regular`. Possible values are `Low` and `Regular`. * `tags` - (Optional) A mapping of tags to assign to the resource. * `zones` - (Optional) A collection of availability zones to spread the Virtual Machines over.