Hello everyone,
We are attempting to build a VM in Azure using Packer and upload it into an Azure Compute Gallery located in the same subscription as the resource groups that Packer uses to build the VM.
On a totally random manner, we hit (around 60 / 70% of the time) a cryptic error when the Deployment attempts to create a Disk associated to the VM. I already contacted the Microsoft Azure support about that and they could not help, only suggested me to ask the Packer community instead.
Here is the error as returned by Packer :
{
"status": "Failed",
"error": {
"code": "DeploymentFailed",
"target": "/subscriptions/***/resourceGroups/pkr-Resource-Group-8l3ej74ngj/providers/Microsoft.Resources/deployments/pkrdp8l3ej74ngj",
"message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",
"details": [
{
"code": "ResourceDeploymentFailure",
"target": "/subscriptions/***/resourceGroups/pkr-Resource-Group-8l3ej74ngj/providers/Microsoft.Compute/virtualMachines/pkrvm8l3ej74ngj",
"message": "The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Failed'.",
"details": [
{
"code": "InvalidParameter",
"message": "The value of parameter networkSpineId is invalid. Target: '/subscriptions/***/resourceGroups/pkr-Resource-Group-8l3ej74ngj/providers/Microsoft.Compute/disks/pkros8l3ej74ngj'."
}
]
}
]
}
}
Has anyone already met this issue? I am totally desperate to find some clue on how to mitigate this…
Here is my (redacted) HCL script:
packer {
required_plugins {
azure = {
source = "github.com/hashicorp/azure"
version = "~> 2"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
}
}
variable destination_image_version {
type = string
}
variable exclude_from_latest {
type = bool
}
variable shared_image_gallery_destination {
type = object({
gallery_name = string
image_name = string
target_region = string
resource_group = string
version_end_of_life_date = string
})
}
variable image {
type = object({
offer = string
publisher = string
sku = string
vm_size = string
security_type = string
vtpm = string
})
}
variable buildenv {
type = object({
virtual_network_name = string
build_resource_group_name = string
virtual_network_resource_group_name = string
virtual_network_subnet_name = string
})
}
source "azure-arm" "runner-vm" {
image_offer = var.image.offer
image_publisher = var.image.publisher
image_sku = var.image.sku
os_type = "Linux"
vm_size = var.image.vm_size
vtpm_enabled = var.image.vtpm
security_type = var.image.security_type
encryption_at_host = "false"
shared_image_gallery_destination {
resource_group = var.shared_image_gallery_destination.resource_group
gallery_name = var.shared_image_gallery_destination.gallery_name
image_name = var.shared_image_gallery_destination.image_name
image_version = var.destination_image_version
storage_account_type = "Standard_LRS"
target_region {
name = var.shared_image_gallery_destination.target_region
}
}
shared_gallery_image_version_exclude_from_latest = var.exclude_from_latest
shared_gallery_image_version_end_of_life_date = var.shared_image_gallery_destination.version_end_of_life_date
use_azure_cli_auth = true
location = "francecentral"
virtual_network_name = var.buildenv.virtual_network_name
virtual_network_resource_group_name = var.buildenv.virtual_network_resource_group_name
virtual_network_subnet_name = var.buildenv.virtual_network_subnet_name
}
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
build {
sources = [
"source.azure-arm.runner-vm"
]
provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
inline = ["/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"]
inline_shebang = "/bin/sh -x"
}
}
Thank you in advance.