Home > Back-end >  virtual machine scale set using terraform without load balancer?
virtual machine scale set using terraform without load balancer?

Time:10-21

I'm trying to deploy a Virtual Machine Scale Set Extension via Terraform but there are few issues here, The requirement was to implement without loadbalancer attached

    resource "azurerm_virtual_machine_scale_set" "example" {
  name                = "mytestscaleset-1"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  # automatic rolling upgrade
  # automatic_os_upgrade = true
  upgrade_policy_mode  = "Rolling"

  rolling_upgrade_policy {
    max_batch_instance_percent              = 20
    max_unhealthy_instance_percent          = 20
    max_unhealthy_upgraded_instance_percent = 5
    pause_time_between_batches              = "PT0S"
  }

  sku {
    name     = "Standard_F2"
    tier     = "Standard"
    capacity = 2
  }

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

  storage_profile_os_disk {
    name              = ""
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  storage_profile_data_disk {
    lun           = 0
    caching       = "ReadWrite"
    create_option = "Empty"
    disk_size_gb  = 10
  }

  os_profile {
    computer_name_prefix = "testvm"
    admin_username       = "myadmin"
  }

  os_profile_linux_config {
    disable_password_authentication = true

    ssh_keys {
      path     = "/home/myadmin/.ssh/authorized_keys"
      key_data = file("C:/Users/User/Downloads/VmSS key/azkey")
    }
  }

  network_profile {
    name    = "terraformnetworkprofile"
    primary = true

    ip_configuration {
      name                                   = "TestIPConfiguration"
      primary                                = true
      subnet_id                              = azurerm_subnet.example.id
      public_ip_address_configuration    {
        name              = "Avx192"
        idle_timeout      = 30
        domain_name_label = "vjst23"
      }
      
    }
  }

  tags = {
    environment = "staging"
  }
}

Once deployed its giving error for health probe

│ Error: compute.VirtualMachineScaleSetsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: Code="BadRequest" Message="Rolling Upgrade mode is not supported for this Virtual Machine Scale Set because a health probe or health extension was not provided."
│
│   with azurerm_virtual_machine_scale_set.example,
│   on Se.tf line 81, in resource "azurerm_virtual_machine_scale_set" "example":
│   81: resource "azurerm_virtual_machine_scale_set" "example" {

How to provide health probe directly if there is no load balancer attached to the deployment?

CodePudding user response:

As you are deploying without load balancer . So , you need to do the below changes in your code:

  1. Change the upgrade_policy_mode = "Rolling" to upgrade_policy_mode = "Manual"/"Automatic"
  2. Remove the below block :
      rolling_upgrade_policy {
        max_batch_instance_percent              = 20
        max_unhealthy_instance_percent          = 20
        max_unhealthy_upgraded_instance_percent = 5
        pause_time_between_batches              = "PT0S"
      }
  • Related