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

Allow auto os upgrades for service fabric #11723

Merged
merged 5 commits into from
May 25, 2021
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
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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This probably requires docs update as well, normally docs state that "Changing this forces a new resource to be created"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, both windows and linux scaleset docs need an update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Docs updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@favoretti - is this OK now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hbuckle LGTM, thank you, but a maintainer has to approve still.

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