Skip to content

Commit

Permalink
Merge pull request #1250 from CoRfr/lowpriorityscalesets
Browse files Browse the repository at this point in the history
Add 'priority' property for VM scale set (fixes #1249)
  • Loading branch information
katbyte authored May 24, 2018
2 parents 3501a86 + 3860a2e commit a2ea8a0
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
13 changes: 13 additions & 0 deletions azurerm/resource_arm_virtual_machine_scale_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource {
ForceNew: true,
},

"priority": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(compute.Low),
string(compute.Regular),
}, true),
},

"os_profile": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -651,6 +661,7 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf
updatePolicy := d.Get("upgrade_policy_mode").(string)
overprovision := d.Get("overprovision").(bool)
singlePlacementGroup := d.Get("single_placement_group").(bool)
priority := d.Get("priority").(string)

scaleSetProps := compute.VirtualMachineScaleSetProperties{
UpgradePolicy: &compute.UpgradePolicy{
Expand All @@ -661,6 +672,7 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf
StorageProfile: &storageProfile,
OsProfile: osProfile,
ExtensionProfile: extensions,
Priority: compute.VirtualMachinePriorityTypes(priority),
},
Overprovision: &overprovision,
SinglePlacementGroup: &singlePlacementGroup,
Expand Down Expand Up @@ -768,6 +780,7 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac

if profile := properties.VirtualMachineProfile; profile != nil {
d.Set("license_type", profile.LicenseType)
d.Set("priority", profile.Priority)

osProfile := flattenAzureRMVirtualMachineScaleSetOsProfile(d, profile.OsProfile)
if err := d.Set("os_profile", osProfile); err != nil {
Expand Down
106 changes: 105 additions & 1 deletion azurerm/resource_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,26 @@ func TestAccAzureRMVirtualMachineScaleSet_overprovision(t *testing.T) {
})
}

func TestAccAzureRMVirtualMachineScaleSet_priority(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSetPriorityTemplate(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, "priority", "Low"),
),
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_MSI(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -820,7 +840,7 @@ func testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(name string, exp
}

if *resp.SinglePlacementGroup != expectedSinglePlacementGroup {
return fmt.Errorf("Bad: Overprovision should have been %t for scale set %v", expectedSinglePlacementGroup, name)
return fmt.Errorf("Bad: SinglePlacementGroup should have been %t for scale set %v", expectedSinglePlacementGroup, name)
}

return nil
Expand Down Expand Up @@ -2577,6 +2597,90 @@ resource "azurerm_virtual_machine_scale_set" "test" {
`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMVirtualMachineScaleSetPriorityTemplate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestrg-%[1]d"
location = "%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"
}
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"
overprovision = false
priority = "Low"
sku {
name = "Standard_D1_v2"
tier = "Standard"
capacity = 1
}
os_profile {
computer_name_prefix = "testvm-%[1]d"
admin_username = "myadmin"
admin_password = "Passwword1234"
}
network_profile {
name = "TestNetworkProfile"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
}
}
storage_profile_os_disk {
name = "os-disk"
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 testAccAzureRMVirtualMachineScaleSetMSITemplate(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down

0 comments on commit a2ea8a0

Please sign in to comment.