I am trying to create images in azure using packer. I am getting the Code="DeploymentFailed" Message="At least one resource deployment operation failed error now and then. If I change the resource group to deploy the image to it starts working and then after few attempts it stops working. Below is the complete error:
Build 'azure-arm.GoldenImage' errored after 2 minutes 20 seconds: polling after CreateOrUpdate: Code="DeploymentFailed" 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." Target="/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/GoldenImage-Packer-Build-Rg/providers/Microsoft.Resources/deployments/pkrdpiiiokqtc33" Details=[{"code":"InvalidResourceReference","details":[],"message":"Resource /subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/ProdPriv/providers/Microsoft.Network/virtualNetworks/ProdPriv/subnets/ProdSubnet1 referenced by resource /subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/Prod-GoldenImage-Packer-Build-Rg/providers/Microsoft.Network/networkInterfaces/pkrniiiiokqtc33 was not found. Please make sure that the referenced resource exists, and that both resources are in the same region."}]
I confirm that everything is in the same region and no doubt about that because same packer template with different variables is working which also gives the same above error sometimes. And I again need to change around the resource groups and images names and then it starts working all of a sudden.
Code:
source "azure-arm" "GoldenImage" {
communicator = "winrm"
image_offer = "WindowsServer"
image_publisher = "MicrosoftWindowsServer"
image_sku = "2019-Datacenter"
managed_image_name = "ProdWin2019DatacenterGoldenImage${var.appType}${local.date}"
managed_image_resource_group_name = var.managed_image_resource_group_name
managed_image_storage_account_type = var.managed_image_storage_account_type
os_type = "Windows"
vm_size = "Standard_D4s_v3" #"Standard_B4ms"
winrm_insecure = true
winrm_timeout = "5m"
winrm_use_ssl = true
winrm_username = "packer"
subscription_id = var.subscription_id
use_azure_cli_auth = true
azure_tags = var.azure_tags
location = var.location
temp_resource_group_name = "${var.Environment}-${var.appType}-RMIS-GoldenImage-Packer-Build-Rg"
virtual_network_name = var.virtual_network_name
virtual_network_subnet_name = var.virtual_network_subnet_name
virtual_network_resource_group_name = var.virtual_network_resource_group_name
}