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

Add 'priority' property for VM scale set #1250

Merged
merged 1 commit into from
May 24, 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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we add "ForceNew" here since a scale set cannot have a mix of Low and Regular VM. Unless Azure will update all pre-existing VM if you change your scaleset from Regular to Low?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we would need a new scale set, so added ForceNew as suggested.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this too!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP!

}

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