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