Skip to content

Commit

Permalink
Allow auto os upgrades for service fabric (#11723)
Browse files Browse the repository at this point in the history
For service fabric scale sets automatic OS upgrade can be enabled without a health probe - docs.microsoft.com/en-gb/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-automatic-upgrade#service-fabric-requirements

In addition, automatic OS upgrade can be enabled without re-creating the scale set (tested in the Azure portal/PowerShell)
  • Loading branch information
hbuckle committed May 25, 2021
1 parent 2b30abb commit ce635ee
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ func TestAccLinuxVirtualMachineScaleSet_extensionsAutomaticUpgradeWithHealthExte
})
}

func TestAccLinuxVirtualMachineScaleSet_extensionAutomaticUpgradeUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.extensionsWithHealthExtension(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password", "extension.0.protected_settings"),
{
Config: r.extensionsAutomaticUpgradeWithHealthExtension(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

func TestAccLinuxVirtualMachineScaleSet_extensionWithTimeBudget(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}
Expand Down Expand Up @@ -275,6 +297,21 @@ func TestAccLinuxVirtualMachineScaleSet_extensionTimeBudgetWithoutExtensionsUpda
})
}

func TestAccLinuxVirtualMachineScaleSet_extensionsAutomaticUpgradeWithServiceFabricExtension(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.extensionsAutomaticUpgradeWithServiceFabricExtension(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password", "extension.0.protected_settings"),
})
}

func (r LinuxVirtualMachineScaleSetResource) extensionDoNotRunExtensionsOnOverProvisionedMachines(data acceptance.TestData, enabled bool) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -712,6 +749,60 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineScaleSetResource) extensionsWithHealthExtension(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
provider "azurerm" {
features {}
}
resource "azurerm_linux_virtual_machine_scale_set" "test" {
name = "acctestvmss-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard_F2"
instances = 1
admin_username = "adminuser"
admin_password = "P@ssword1234!"
disable_password_authentication = false
upgrade_mode = "Automatic"
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
network_interface {
name = "example"
primary = true
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.test.id
}
}
extension {
name = "HealthExtension"
publisher = "Microsoft.ManagedServices"
type = "ApplicationHealthLinux"
type_handler_version = "1.0"
auto_upgrade_minor_version = true
settings = jsonencode({
protocol = "https"
port = 443
})
}
tags = {
accTest = "true"
}
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineScaleSetResource) extensionsAutomaticUpgradeWithHealthExtension(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down Expand Up @@ -886,3 +977,98 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
}
`, template, data.RandomInteger, duration)
}

func (r LinuxVirtualMachineScaleSetResource) extensionsAutomaticUpgradeWithServiceFabricExtension(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s
provider "azurerm" {
features {}
}
resource "azurerm_service_fabric_cluster" "test" {
name = "acctest-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
reliability_level = "Silver"
upgrade_mode = "Manual"
cluster_code_version = "8.0.516.9590"
vm_image = "Windows"
management_endpoint = "http://example:80"
node_type {
name = "backend"
instance_count = 5
is_primary = true
client_endpoint_port = 2020
http_endpoint_port = 80
durability_level = "Silver"
}
}
resource "azurerm_linux_virtual_machine_scale_set" "test" {
name = "acctestvmss-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard_F2"
instances = 1
admin_username = "adminuser"
admin_password = "P@ssword1234!"
upgrade_mode = "Automatic"
overprovision = false
disable_password_authentication = false
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
os_disk {
storage_account_type = "Standard_LRS"
caching = "ReadWrite"
}
network_interface {
name = "example"
primary = true
ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.test.id
}
}
automatic_os_upgrade_policy {
disable_automatic_rollback = true
enable_automatic_os_upgrade = true
}
rolling_upgrade_policy {
max_batch_instance_percent = 20
max_unhealthy_instance_percent = 20
max_unhealthy_upgraded_instance_percent = 20
pause_time_between_batches = "PT0S"
}
extension {
name = "ServiceFabric"
publisher = "Microsoft.Azure.ServiceFabric"
type = "ServiceFabricLinuxNode"
type_handler_version = "1.1"
auto_upgrade_minor_version = true
settings = jsonencode({
clusterEndpoint = azurerm_service_fabric_cluster.test.cluster_endpoint
nodeTypeRef = "backend"
durabilityLevel = "Silver"
enableParallelJobs = true
})
}
}
`, template, data.RandomInteger, data.RandomInteger)
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,6 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta inte
virtualMachineProfile.ExtensionProfile.ExtensionsTimeBudget = utils.String(v.(string))
}

// otherwise the service return the error:
// Automatic OS Upgrade is not supported for this Virtual Machine Scale Set because a health probe or health extension was not specified.
if upgradeMode == compute.Automatic && len(automaticOSUpgradePolicyRaw) > 0 {
if *automaticOSUpgradePolicy.EnableAutomaticOSUpgrade && (healthProbeId == "" && !hasHealthExtension) {
return fmt.Errorf("`health_probe_id` must be set or a health extension must be specified when `upgrade_mode` is set to %q and `automatic_os_upgrade_policy` block exists", string(upgradeMode))
}
}

// otherwise the service return the error:
// Rolling Upgrade mode is not supported for this Virtual Machine Scale Set because a health probe or health extension was not provided.
if upgradeMode == compute.Rolling && (healthProbeId == "" && !hasHealthExtension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,20 +1236,17 @@ func VirtualMachineScaleSetAutomatedOSUpgradePolicySchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// TODO: should these be optional + defaulted?
"disable_automatic_rollback": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},
"enable_automatic_os_upgrade": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},
},
},
Expand Down
Loading

0 comments on commit ce635ee

Please sign in to comment.