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

r/(linux|windows)_virtual_machine_scale_set - Add support for scale_in_policy and terminate_notification #5391

Conversation

ArcturusZhang
Copy link
Contributor

@ArcturusZhang ArcturusZhang commented Jan 14, 2020

This PR add scale_in_policy and terminate_notification to both azurerm_linux_virtual_machine_scale_set and azurerm_windows_virtual_machine_scale_set.
You can find the docs for them here:
scale_in_policy: https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-scale-in-policy
terminate_notification: https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-terminate-notification

Fixes: #5738

Terraform usage example:

resource "azurerm_linux_virtual_machine_scale_set" "example" {
  name                 = "${var.prefix}-vmss"
  location             = azurerm_resource_group.example.location
  resource_group_name  = azurerm_resource_group.example.name
  overprovision        = true
  upgrade_mode         = "Manual"

  sku       = "Standard_D1_v2"
  instances = 2

  admin_username       = "myadmin"
  admin_password       = "Passwword1234"

  disable_password_authentication = false

  network_interface {
    name    = "internal"
    primary = true

    ip_configuration {
      name                                   = "internal"
      subnet_id                              = azurerm_subnet.example.id
      load_balancer_backend_address_pool_ids = [azurerm_lb_backend_address_pool.example.id]
      primary                                = true
    }
  }

  os_disk {
    disk_size_gb         = 30
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  scale_in_policy = "Default"

  terminate_notification {
    enabled = true
    timeout = "PT5M"
  }
}

@ArcturusZhang
Copy link
Contributor Author

Also, unfortunately despite I added acc-tests for both new features, but those acc-tests cannot pass, neither could the existing acc-tests for VMSS.
I got the following errors for those acc-tests:


=== RUN   TestAccAzureRMWindowsVirtualMachineScaleSet_otherScaleInPolicy
=== PAUSE TestAccAzureRMWindowsVirtualMachineScaleSet_otherScaleInPolicy
=== CONT  TestAccAzureRMWindowsVirtualMachineScaleSet_otherScaleInPolicy
--- FAIL: TestAccAzureRMWindowsVirtualMachineScaleSet_otherScaleInPolicy (315.39s)
    testing.go:569: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: azurerm_windows_virtual_machine_scale_set.test
          additional_capabilities.#:                                                             "0" => "0"
          additional_unattend_config.#:                                                          "0" => "0"
          admin_password:                                                                        "P@ssword1234!" => "P@ssword1234!"
          admin_username:                                                                        "adminuser" => "adminuser"
          automatic_os_upgrade_policy.#:                                                         "0" => "0"
          boot_diagnostics.#:                                                                    "0" => "0"
          computer_name_prefix:                                                                  "acctvm20" => "acctvm20"
          data_disk.#:                                                                           "0" => "0"
          do_not_run_extensions_on_overprovisioned_machines:                                     "false" => "false"
          enable_automatic_updates:                                                              "true" => "true"
          eviction_policy:                                                                       "" => ""
          health_probe_id:                                                                       "" => ""
          id:                                                                                    "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114130928638737/providers/Microsoft.Compute/virtualMachineScaleSets/acctvm20" => "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114130928638737/providers/Microsoft.Compute/virtualMachineScaleSets/acctvm20"
          identity.#:                                                                            "0" => "0"
          instances:                                                                             "1" => "1"
          license_type:                                                                          "" => ""
          location:                                                                              "westus2" => "westus2"
          max_bid_price:                                                                         "-1" => "-1"
          name:                                                                                  "acctvm20" => "acctvm20"
          network_interface.#:                                                                   "1" => "1"
          network_interface.0.dns_servers.#:                                                     "" => "0"
          network_interface.0.enable_accelerated_networking:                                     "false" => "false"
          network_interface.0.enable_ip_forwarding:                                              "false" => "false"
          network_interface.0.ip_configuration.#:                                                "1" => "1"
          network_interface.0.ip_configuration.0.application_gateway_backend_address_pool_ids.#: "" => "0"
          network_interface.0.ip_configuration.0.application_security_group_ids.#:               "" => "0"
          network_interface.0.ip_configuration.0.load_balancer_backend_address_pool_ids.#:       "" => "0"
          network_interface.0.ip_configuration.0.load_balancer_inbound_nat_rules_ids.#:          "" => "0"
          network_interface.0.ip_configuration.0.name:                                           "internal" => "internal"
          network_interface.0.ip_configuration.0.primary:                                        "true" => "true"
          network_interface.0.ip_configuration.0.public_ip_address.#:                            "0" => "0"
          network_interface.0.ip_configuration.0.subnet_id:                                      "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114130928638737/providers/Microsoft.Network/virtualNetworks/acctestnw-200114130928638737/subnets/internal" => "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114130928638737/providers/Microsoft.Network/virtualNetworks/acctestnw-200114130928638737/subnets/internal"
          network_interface.0.ip_configuration.0.version:                                        "IPv4" => "IPv4"
          network_interface.0.name:                                                              "example" => "example"
          network_interface.0.network_security_group_id:                                         "" => ""
          network_interface.0.primary:                                                           "true" => "true"
          os_disk.#:                                                                             "1" => "1"
          os_disk.0.caching:                                                                     "ReadWrite" => "ReadWrite"
          os_disk.0.diff_disk_settings.#:                                                        "0" => "0"
          os_disk.0.disk_size_gb:                                                                "127" => ""
          os_disk.0.storage_account_type:                                                        "Standard_LRS" => "Standard_LRS"
          os_disk.0.write_accelerator_enabled:                                                   "false" => "false"
          overprovision:                                                                         "true" => "true"
          plan.#:                                                                                "0" => "0"
          priority:                                                                              "Regular" => "Regular"
          provision_vm_agent:                                                                    "true" => "true"
          proximity_placement_group_id:                                                          "" => ""
          resource_group_name:                                                                   "acctestRG-200114130928638737" => "acctestRG-200114130928638737"
          rolling_upgrade_policy.#:                                                              "0" => "0"
          scale_in_policy:                                                                       "Default" => "Default"
          secret.#:                                                                              "0" => "0"
          single_placement_group:                                                                "true" => "true"
          sku:                                                                                   "Standard_F2" => "Standard_F2"
          source_image_id:                                                                       "" => ""
          source_image_reference.#:                                                              "1" => "1"
          source_image_reference.0.offer:                                                        "WindowsServer" => "WindowsServer"
          source_image_reference.0.publisher:                                                    "MicrosoftWindowsServer" => "MicrosoftWindowsServer"
          source_image_reference.0.sku:                                                          "2019-Datacenter" => "2019-Datacenter"
          source_image_reference.0.version:                                                      "latest" => "latest"
          terminate_notification.#:                                                              "0" => "0"
          terraform_should_roll_instances_when_required:                                         "true" => "true"
          timezone:                                                                              "" => ""
          unique_id:                                                                             "b07bc94f-1bf7-45c1-9d20-59f010ed6be1" => "b07bc94f-1bf7-45c1-9d20-59f010ed6be1"
          upgrade_mode:                                                                          "Manual" => "Manual"
          winrm_listener.#:                                                                      "0" => "0"
          zone_balance:                                                                          "false" => "false"

And one of the existing acc-test gives the same error:

=== RUN   TestAccAzureRMLinuxVirtualMachineScaleSet_otherSecret
=== PAUSE TestAccAzureRMLinuxVirtualMachineScaleSet_otherSecret
=== CONT  TestAccAzureRMLinuxVirtualMachineScaleSet_otherSecret
--- FAIL: TestAccAzureRMLinuxVirtualMachineScaleSet_otherSecret (522.18s)
    testing.go:569: Step 0 error: After applying this step, the plan was not empty:

        DIFF:

        UPDATE: azurerm_linux_virtual_machine_scale_set.test
          additional_capabilities.#:                                                             "0" => "0"
          admin_password:                                                                        "P@ssword1234!" => "P@ssword1234!"
          admin_ssh_key.#:                                                                       "0" => "0"
          admin_username:                                                                        "adminuser" => "adminuser"
          automatic_os_upgrade_policy.#:                                                         "0" => "0"
          boot_diagnostics.#:                                                                    "0" => "0"
          computer_name_prefix:                                                                  "acctestvmss-200114113936809647" => "acctestvmss-200114113936809647"
          data_disk.#:                                                                           "0" => "0"
          disable_password_authentication:                                                       "false" => "false"
          do_not_run_extensions_on_overprovisioned_machines:                                     "false" => "false"
          eviction_policy:                                                                       "" => ""
          health_probe_id:                                                                       "" => ""
          id:                                                                                    "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114113936809647/providers/Microsoft.Compute/virtualMachineScaleSets/acctestvmss-200114113936809647" => "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114113936809647/providers/Microsoft.Compute/virtualMachineScaleSets/acctestvmss-200114113936809647"
          identity.#:                                                                            "0" => "0"
          instances:                                                                             "1" => "1"
          location:                                                                              "westus2" => "westus2"
          max_bid_price:                                                                         "-1" => "-1"
          name:                                                                                  "acctestvmss-200114113936809647" => "acctestvmss-200114113936809647"
          network_interface.#:                                                                   "1" => "1"
          network_interface.0.dns_servers.#:                                                     "" => "0"
          network_interface.0.enable_accelerated_networking:                                     "false" => "false"
          network_interface.0.enable_ip_forwarding:                                              "false" => "false"
          network_interface.0.ip_configuration.#:                                                "1" => "1"
          network_interface.0.ip_configuration.0.application_gateway_backend_address_pool_ids.#: "" => "0"
          network_interface.0.ip_configuration.0.application_security_group_ids.#:               "" => "0"
          network_interface.0.ip_configuration.0.load_balancer_backend_address_pool_ids.#:       "" => "0"
          network_interface.0.ip_configuration.0.load_balancer_inbound_nat_rules_ids.#:          "" => "0"
          network_interface.0.ip_configuration.0.name:                                           "internal" => "internal"
          network_interface.0.ip_configuration.0.primary:                                        "true" => "true"
          network_interface.0.ip_configuration.0.public_ip_address.#:                            "0" => "0"
          network_interface.0.ip_configuration.0.subnet_id:                                      "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114113936809647/providers/Microsoft.Network/virtualNetworks/acctestnw-200114113936809647/subnets/internal" => "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114113936809647/providers/Microsoft.Network/virtualNetworks/acctestnw-200114113936809647/subnets/internal"
          network_interface.0.ip_configuration.0.version:                                        "IPv4" => "IPv4"
          network_interface.0.name:                                                              "example" => "example"
          network_interface.0.network_security_group_id:                                         "" => ""
          network_interface.0.primary:                                                           "true" => "true"
          os_disk.#:                                                                             "1" => "1"
          os_disk.0.caching:                                                                     "ReadWrite" => "ReadWrite"
          os_disk.0.diff_disk_settings.#:                                                        "0" => "0"
          os_disk.0.disk_size_gb:                                                                "30" => ""
          os_disk.0.storage_account_type:                                                        "Standard_LRS" => "Standard_LRS"
          os_disk.0.write_accelerator_enabled:                                                   "false" => "false"
          overprovision:                                                                         "true" => "true"
          plan.#:                                                                                "0" => "0"
          priority:                                                                              "Regular" => "Regular"
          provision_vm_agent:                                                                    "true" => "true"
          proximity_placement_group_id:                                                          "" => ""
          resource_group_name:                                                                   "acctestRG-200114113936809647" => "acctestRG-200114113936809647"
          rolling_upgrade_policy.#:                                                              "0" => "0"
          scale_in_policy:                                                                       "Default" => "Default"
          secret.#:                                                                              "1" => "1"
          secret.0.certificate.#:                                                                "1" => "1"
          secret.0.certificate.0.url:                                                            "https://acctestkeyvaultxww3c.vault.azure.net/secrets/first/710a614f74eb4bfeb39e389035a0b1d1" => "https://acctestkeyvaultxww3c.vault.azure.net/secrets/first/710a614f74eb4bfeb39e389035a0b1d1"
          secret.0.key_vault_id:                                                                 "/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114113936809647/providers/Microsoft.KeyVault/vaults/acctestkeyvaultxww3c" => 
"/subscriptions/67a9759d-d099-4aa8-8675-e6cfd669c3f4/resourceGroups/acctestRG-200114113936809647/providers/Microsoft.KeyVault/vaults/acctestkeyvaultxww3c"
          single_placement_group:                                                                "true" => "true"
          sku:                                                                                   "Standard_F2" => "Standard_F2"
          source_image_id:                                                                       "" => ""
          source_image_reference.#:                                                              "1" => "1"
          source_image_reference.0.offer:                                                        "UbuntuServer" => "UbuntuServer"
          source_image_reference.0.publisher:                                                    "Canonical" => "Canonical"
          source_image_reference.0.sku:                                                          "16.04-LTS" => "16.04-LTS"
          source_image_reference.0.version:                                                      "latest" => "latest"
          terminate_notification.#:                                                              "0" => "0"
          terraform_should_roll_instances_when_required:                                         "true" => "true"
          unique_id:                                                                             "c423c74a-2d15-4060-942e-929ac86ce6e3" => "c423c74a-2d15-4060-942e-929ac86ce6e3"
          upgrade_mode:                                                                          "Manual" => "Manual"
          zone_balance:                                                                          "false" => "false"

@tombuildsstuff tombuildsstuff self-assigned this Jan 14, 2020
@ArcturusZhang ArcturusZhang force-pushed the VMSS-Scale-in-policy-And-Terminate-Notification branch from 601a902 to 7779d6f Compare January 16, 2020 05:00
@ArcturusZhang
Copy link
Contributor Author

Some information about the scale_in_policy, the swagger (as well as the SDK) are displaying this field as an array, but it only accepts one value for now.
In the future, this may support more values in the array (but no guarantee, and not documented), therefore should we leave some room for this improvement and make the scale_in_policy an array but accept only on element for now?

@ArcturusZhang ArcturusZhang changed the title Add support for scale_in_policy and terminate_notification in VMSS 2.0 r/(linux|windows)_virtual_machine_scale_set - Add support for scale_in_policy and terminate_notification Jan 17, 2020
@tombuildsstuff tombuildsstuff added this to the v2.0.0 milestone Jan 17, 2020
@ArcturusZhang ArcturusZhang force-pushed the VMSS-Scale-in-policy-And-Terminate-Notification branch 2 times, most recently from 52f2ec6 to 2fb9a00 Compare February 4, 2020 03:33
@ArcturusZhang
Copy link
Contributor Author

Rebased to master and conflicts resolved

@ArcturusZhang ArcturusZhang force-pushed the VMSS-Scale-in-policy-And-Terminate-Notification branch from 2fb9a00 to 3fcec12 Compare February 14, 2020 09:28
@tombuildsstuff tombuildsstuff modified the milestones: v2.0.0, v2.1.0 Feb 17, 2020
@ArcturusZhang ArcturusZhang force-pushed the VMSS-Scale-in-policy-And-Terminate-Notification branch from 3fcec12 to f03f175 Compare February 25, 2020 07:16
@ArcturusZhang ArcturusZhang force-pushed the VMSS-Scale-in-policy-And-Terminate-Notification branch from f03f175 to 23c7a25 Compare March 2, 2020 09:47
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Hi @ArcturusZhang
Thanks for this. There's a failing test due to a typo in the template section, but if you can update that then this LGTM 👍

@ArcturusZhang
Copy link
Contributor Author

Hi @jackofallops I have fixed the typo, please have a look, thanks!

@tombuildsstuff tombuildsstuff modified the milestones: v2.1.0, v2.2.0 Mar 11, 2020
@jackofallops
Copy link
Member

Hi @ArcturusZhang
Thanks for the update - that test now passes successfully. There are some other failures that appear to be unrelated, so I'll fix those up in another PR after merging this.

@jackofallops jackofallops merged commit 5821852 into hashicorp:master Mar 17, 2020
jackofallops added a commit that referenced this pull request Mar 17, 2020
katbyte added a commit that referenced this pull request Mar 17, 2020
@ArcturusZhang ArcturusZhang deleted the VMSS-Scale-in-policy-And-Terminate-Notification branch March 18, 2020 08:43
@ghost
Copy link

ghost commented Mar 19, 2020

This has been released in version 2.2.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.2.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Apr 17, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azurerm_virtual_machine_scale_set need ability to override default scale-in policy
3 participants