Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMSS: support for eviction policy #2226

Merged
merged 1 commit into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
}, true),
},

"eviction_policy": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(compute.Deallocate),
string(compute.Delete),
}, false),
},

"os_profile": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -782,6 +792,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{
Expand All @@ -800,6 +811,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
Expand Down Expand Up @@ -912,7 +927,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 {
Expand Down
117 changes: 117 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ func TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) {
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
// testing default scaleset values
testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(resourceName, true),
resource.TestCheckResourceAttr(resourceName, "eviction_policy", ""),
),
},
{
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"),
),
},
{
Expand Down Expand Up @@ -582,6 +609,7 @@ func TestAccAzureRMVirtualMachineScaleSet_priority(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMVirtualMachineScaleSetExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "priority", "Low"),
resource.TestCheckResourceAttr(resourceName, "eviction_policy", "Deallocate"),
),
},
},
Expand Down Expand Up @@ -1295,6 +1323,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" {
Expand Down Expand Up @@ -3280,6 +3396,7 @@ resource "azurerm_virtual_machine_scale_set" "test" {
upgrade_policy_mode = "Manual"
overprovision = false
priority = "Low"
eviction_policy = "Deallocate"

sku {
name = "Standard_D1_v2"
Expand Down
57 changes: 44 additions & 13 deletions website/docs/r/virtual_machine_scale_set.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -264,34 +264,65 @@ resource "azurerm_virtual_machine_scale_set" "test" {
The following arguments are supported:

* `name` - (Required) Specifies the name of the virtual machine scale set resource. Changing this forces a new resource to be created.

* `resource_group_name` - (Required) The name of the resource group in which to create the virtual machine scale set. Changing this forces a new resource to be created.

* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created.

* `network_profile` - (Required) A collection of network profile block as documented below.

* `os_profile` - (Required) A Virtual Machine OS Profile block 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.

* `sku` - (Required) A sku block as documented below.

* `storage_profile_os_disk` - (Required) A storage profile os disk 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`.

* `boot_diagnostics` - (Optional) A boot diagnostics profile block as referenced below.

* `extension` - (Optional) Can be specified multiple times to add extension profiles to the scale set. Each `extension` block supports the fields documented below.

* `eviction_policy` - (Optional) Specifies the eviction policy for Virtual Machines in this Scale Set. Possible values are `Deallocate` and `Delete`.

-> **NOTE:** `eviction_policy` can only be set when `priority` is set to `Low`.

* `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.
* `storage_profile_os_disk` - (Required) A storage profile os disk block as documented below

* `overprovision` - (Optional) Specifies whether the virtual machine scale set should be overprovisioned.

* `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`.

* `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_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`.

* `tags` - (Optional) A mapping of tags to assign to the resource.

* `zones` - (Optional) A collection of availability zones to spread the Virtual Machines over.

-> **Please Note**: Availability Zones are [only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview).

---

`sku` supports the following:

* `name` - (Required) Specifies the size of virtual machines in a scale set.
Expand Down