Azure VMSS created via Terraform for Azure DevOps pipelines – custom script does not run on instance startup

I created Azure VMSS and i want to use it in Azure DevOps pipelines.

ADO part works perfect but when i run task, i got an error:

Starting: TerraformInstaller
==============================================================================
Task         : Terraform tool installer
Description  : Find in cache or download a specific version of Terraform and prepend it to the PATH
Version      : 1.216.25
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://aka.ms/AAf1a0p)
==============================================================================
Downloading: https://releases.hashicorp.com/terraform/1.8.1/terraform_1.8.1_linux_amd64.zip
Extracting archive
##[error]Error: Unable to locate executable file: 'unzip'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
Finishing: TerraformInstaller

In my Azure VMSS repo i have a file:

#!/bin/sh
###################################
# Prerequisites

sudo apt-get -y install zip
sudo apt-get -y install unzip

# Update the list of packages
sudo apt-get update

# Install pre-requisite packages.
sudo apt-get install -y wget apt-transport-https software-properties-common

# Get the version of Ubuntu
source /etc/os-release

# Download the Microsoft repository keys
wget -q https://packages.microsoft.com/config/ubuntu/$VERSION_ID/packages-microsoft-prod.deb

# Register the Microsoft repository keys
sudo dpkg -i packages-microsoft-prod.deb

# Delete the Microsoft repository keys file
rm packages-microsoft-prod.deb

# Update the list of packages after we added packages.microsoft.com
sudo apt-get update

###################################
# Install PowerShell
sudo apt-get install -y powershell

# Update the latest packages and make sure certs, curl, https transport, and related packages are updated.
sudo apt-get update
sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg

# Download and install the Microsoft signing key.
curl -sL https://packages.microsoft.com/keys/microsoft.asc | 
    gpg --dearmor | 
    sudo tee /etc/apt/trusted.gpg.d/microsoft.asc.gpg > /dev/null

# Add the software repository of the Azure CLI.
AZ_REPO=$(lsb_release -cs)
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | 
    sudo tee /etc/apt/sources.list.d/azure-cli.list

# Update the repository information and install the azure-cli package.
sudo apt-get update
sudo apt-get install azure-cli

To install zip, unzip, Azure CLI and powershell. But it seems it does not work.

Here is my extension code:

resource "azurerm_linux_virtual_machine_scale_set" "vmss" {
  lifecycle {
    ignore_changes = [ 
      tags,
      instances
    ]
  }

  name                 = local.vmss_name
  resource_group_name  = local.rg_name
  location             = local.rg_location
  sku                  = local.vmss_sku_tier
  instances            = 2
  admin_username       = var.vmss_user
  admin_password       = var.vmss_password
  computer_name_prefix = "vm-"
  upgrade_mode         = "Manual"
  overprovision        = false
  disable_password_authentication = false

  automatic_instance_repair {
    enabled      = false
    grace_period = "PT30M"
  }

  scale_in {
    force_deletion_enabled = false
    rule                   = "Default"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "0001-com-ubuntu-server-jammy"
    sku       = local.vmss_sku_name
    version   = "latest"
  }

  os_disk {
    storage_account_type = "Premium_LRS"
    caching              = "ReadWrite"
    disk_size_gb         = 127
  }
  
  network_interface {
    name    = local.vmss_nic_name
    primary = true

    ip_configuration {
      name      = local.vmss_ipconfig
      primary   = true
      subnet_id = data.azurerm_subnet.subnet.id
    }
  }

  depends_on = [
    azurerm_resource_group.rg
  ]
}


resource "azurerm_virtual_machine_scale_set_extension" "cloud_init" {
  name                         = "cloud-init"
  virtual_machine_scale_set_id = azurerm_linux_virtual_machine_scale_set.vmss.id
  publisher                    = "Microsoft.Azure.Extensions"
  type                         = "CustomScript"
  type_handler_version         = "2.0"

  settings = <<SETTINGS
    {
        "script": "${filebase64("cloud-init.sh")}"
    }
SETTINGS

  depends_on = [ azurerm_linux_virtual_machine_scale_set.vmss ]
}

Why my shell script is not executed when instance is getting up and zip/unzip is not installed? I have almost identical code for VMSS for windows with script:

resource "azurerm_virtual_machine_scale_set_extension" "cloud_init" {
  name                         = "cloud-init"
  virtual_machine_scale_set_id = azurerm_windows_virtual_machine_scale_set.vmss.id
  publisher                    = "Microsoft.Compute"
  type                         = "CustomScriptExtension"
  type_handler_version         = "1.9"

  settings = <<SETTINGS
  {
     "commandToExecute": "powershell -encodedCommand ${textencodebase64(file("cloud-init.ps1"), "UTF-16LE")}"
  }
  SETTINGS

  depends_on = [ azurerm_windows_virtual_machine_scale_set.vmss ]
}

And for windows VMSS, it works like a charm

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật