hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

azurerm_linux_virtual_machine_scale_set upgrade_mode default optional values force a replacement #14423

Open OlivierDupre opened 2 years ago

OlivierDupre commented 2 years ago

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

terraform 1.0.7 azurerm v2.81.0

Affected Resource(s)

azurerm_linux_virtual_machine_scale_set

Terraform Configuration Files

resource "azurerm_linux_virtual_machine_scale_set" "vmss-nva" {
  location                                          = azurerm_resource_group.rg-nva.location
  resource_group_name                               = azurerm_resource_group.rg-nva.name
  computer_name_prefix                              = "vmss-nvas"
  name                                              = "vmss-nva"
  upgrade_mode                                      =  null
  sku                                               = "Standard_D2ds_v4"
  instances                                         = 2
  do_not_run_extensions_on_overprovisioned_machines = false
  disable_password_authentication                   = true
  encryption_at_host_enabled                        = false
  eviction_policy                                   = "Deallocate"
  max_bid_price                                     = -1
  overprovision                                     = false
  priority                                          = "Spot"
  provision_vm_agent                                = true
  scale_in_policy                                   = "Default"
  single_placement_group                            = false
  tags                                              = {}
  zone_balance                                      = false
  zones = [
    "1",
    "2",
  ]

  admin_username = "azureuser"

  admin_ssh_key {
    public_key = (sensitive data)
    username   = "azureuser"
  }

  automatic_instance_repair {
    enabled      = false
    grace_period = "PT30M"
  }

  boot_diagnostics {}

  network_interface {
    name                          = "vnet-hub-nic01"
    enable_accelerated_networking = false
    enable_ip_forwarding          = false
    network_security_group_id     = azurerm_network_security_group.nsg-vmss-nva.id
    primary                       = true

    ip_configuration {
      name                                         = "vnet-hub-nic01-defaultIpConfiguration"
      application_gateway_backend_address_pool_ids = []
      application_security_group_ids               = []
      load_balancer_backend_address_pool_ids = [
        azurerm_lb_backend_address_pool.bepool-vmss-nva.id,
      ]
      load_balancer_inbound_nat_rules_ids = []
      primary                             = true
      subnet_id                           = azurerm_subnet.snet-nva.id
      version                             = "IPv4"

      public_ip_address {
        idle_timeout_in_minutes = 15
        name                    = "publicIp-vnet-hub-nic01"
      }
    }
  }

Debug Output

Terraform always detect changes on upgrade_mode.

I have created manually this Virtual Machine Scale Set inthe Azure portal and imported it in Terraform. The state defines "upgrade_mode": null while the azurerm_linux_virtual_machine_scale_set resource defaults the value for this field to "Manual" (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine_scale_set#upgrade_mode)

Terraform detected the following changes when I run terraform plan

  # azurerm_linux_virtual_machine_scale_set.vmss-nva must be replaced
-/+ resource "azurerm_linux_virtual_machine_scale_set" "vmss-nva" {
        name                                              = "vmss-nva"
      ~ platform_fault_domain_count                       = 1 -> (known after apply)
      - tags                                              = {} -> null
      + upgrade_mode                                      = "Manual" # forces replacement
        # (19 unchanged attributes hidden)

Actual Behaviour

Always replaced with a destroy / create

Steps to Reproduce

Create a Virtual Machine Scale set manually. Import it with Terraform. Retrieve the state in a tf file with terraform show -no-color > vmss.tf`` Run aterraform plan`

I think there is a problem with default optional values.

tombuildsstuff commented 2 years ago

This'll want fixing in the Importer for Linux & Windows VM's