I get error when i try to run the below packer file

{
“variables”: {
“managed_image_name”: “my-test-image”,
“managed_image_rg”: “Test_Image”,
“base_image_id”: “MicrosoftWindowsDesktop:windows-11:win11-22h2-avd:22621.1105.230107”,
“identity_id”: “/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourcegroups/Test_Image/providers/Microsoft.ManagedIdentity/userAssignedIdentities/Test”,
“vnet_name”: “Test_Vnet”,
“subnet_id”: “/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourceGroups/Test_Image/providers/Microsoft.Network/virtualNetworks/Test_Vnet/subnets/Test”,
“nsg_name”: “Test_NSG”
},
“builders”: [
{
“type”: “azure-arm”,
“subscription_id”: “66118adc-b709-4533-a6be-252b2f04211e”,
“managed_identity_resource_id”: “{{user identity_id}}”,
“managed_image_resource_group_name”: “{{user managed_image_rg}}”,
“managed_image_name”: “{{user managed_image_name}}”,
“os_type”: “Windows”,
“base_image_id”: “{{user base_image_id}}”,
“vm_size”: “Standard_DS2_v2”,
“os_disk_size_gb”: 128,
“virtual_network_name”: “{{user vnet_name}}”,
“subnet_id”: “{{user subnet_id}}”,
“security_group_name”: “{{user nsg_name}}”,
“azure_tags”: {
“dept”: “Test”
},
“communicator”: “winrm”,
“winrm_use_ssl”: true,
“winrm_insecure”: true,
“winrm_timeout”: “1h”

  }
]

}

I get these error and i don’t why and help me solve them please
4 errors occurred:
* unknown configuration key: ‘“base_image_id”’
* unknown configuration key: ‘“managed_identity_resource_id”’
* unknown configuration key: ‘“security_group_name”’
* unknown configuration key: ‘“subnet_id”’

  1. Could you use this…
    ```plain
    Code goes here
    ```
    for code in your post?

  2. Can you use Hcl(2) instead of json?

variable “base_image_id” {
type = string
default = “MicrosoftWindowsDesktop:windows-11:win11-22h2-avd:22621.1105.230107”
}

variable “identity_id” {
type = string
default = “/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourcegroups/Test_Image/providers/Microsoft.ManagedIdentity/userAssignedIdentities/Test”
}

variable “managed_image_name” {
type = string
default = “my-test-image”
}

variable “managed_image_rg” {
type = string
default = “Test_Image”
}

variable “nsg_name” {
type = string
default = “Test_NSG”
}

variable “subnet_id” {
type = string
default = “/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourceGroups/Test_Image/providers/Microsoft.Network/virtualNetworks/Test_Vnet/subnets/Test”
}

variable “vnet_name” {
type = string
default = “Test_Vnet”
}

source “azure-arm” “autogenerated_1” {
azure_tags = {
dept = “Test”
}
base_image_id = “{var.base_image_id}" communicator = "winrm" managed_identity_resource_id = "{var.identity_id}”
managed_image_name = “{var.managed_image_name}" managed_image_resource_group_name = "{var.managed_image_rg}”
os_disk_size_gb = 128
os_type = “Windows”
security_group_name = “{var.nsg_name}" subnet_id = "{var.subnet_id}”
subscription_id = “Free Trial”
virtual_network_name = “${var.vnet_name}”
vm_size = “Standard_DS2_v2”
winrm_insecure = true
winrm_timeout = “1h”
winrm_use_ssl = true
}

build {
sources = [“source.azure-arm.autogenerated_1”]

}

I have added Hcl2 here still same error so if i use clientID,Client secret,TenantID and Subscribtion ID instead of managed identity and remove NSG, use subnet name instead of Subnet_id and given image_sku,publishers instead if base image id i can Run the script but im getting Winrm timeout i dont know how to fix WinRM issue

variable "base_image_id" {
  type = string
  default = "MicrosoftWindowsDesktop:windows-11:win11-22h2-avd:22621.1105.230107"
}

variable "identity_id" {
  type = string
  default = "/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourcegroups/Test_Image/providers/Microsoft.ManagedIdentity/userAssignedIdentities/Test"
}

variable "managed_image_name" {
  type = string
  default = "my-test-image"
}

variable "managed_image_rg" {
  type = string
  default = "Test_Image"
}

variable "nsg_name" {
  type = string
  default = "Test_NSG"
}

variable "subnet_id" {
  type = string
  default = "/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourceGroups/Test_Image/providers/Microsoft.Network/virtualNetworks/Test_Vnet/subnets/Test"
}

variable "vnet_name" {
  type = string
  default = "Test_Vnet"
}

source "azure-arm" "autogenerated_1" {
  azure_tags = {
    dept = "Test"
  }
  base_image_id = "var.baseimageid"
  communicator="winrm"
  managedidentityresourceid="{var.identity_id}"
  managed_image_name = "var.managedimagename"
  managedimageresourcegroupname="{var.managed_image_rg}”
  os_disk_size_gb = 128
  os_type = "Windows"
  security_group_name = “var.nsgname"
  subnetid="{var.subnet_id}"
  subscription_id = "Free Trial"
  virtual_network_name = "${var.vnet_name}"
  vm_size = "Standard_DS2_v2"
  winrm_insecure = true
  winrm_timeout = "1h"
  winrm_use_ssl = true
}

build {
    sources = ["source.azure-arm.autogenerated_1"]
}

Alright, I don’t know what you did, but the above i created is readable to me.

Edit the following:

  • "var.baseimageid"var.base_image_id
  • "{var.identity_id}""${var.identity_id}"

And do the same for similar errors.


variable "base_image_id" {
  type    = string
  default = "MicrosoftWindowsDesktop:windows-11:win11-22h2-avd:22621.1105.230107"
}

variable "identity_id" {
  type    = string
  default = "/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourcegroups/Test_Image/providers/Microsoft.ManagedIdentity/userAssignedIdentities/Test"
}

variable "managed_image_name" {
  type    = string
  default = "my-test-image"
}

variable "managed_image_rg" {
  type    = string
  default = "Test_Image"
}

variable "nsg_name" {
  type    = string
  default = "Test_NSG"
}

variable "subnet_id" {
  type    = string
  default = "/subscriptions/66118adc-b709-4533-a6be-252b2f04211e/resourceGroups/Test_Image/providers/Microsoft.Network/virtualNetworks/Test_Vnet/subnets/Test"
}

variable "vnet_name" {
  type    = string
  default = "Test_Vnet"
}

source "azure-arm" "autogenerated_1" {
  azure_tags = {
    dept = "Test"
  }
  base_image_id                     = "${var.base_image_id}"
  communicator                      = "winrm"
  managed_identity_resource_id      = "${var.identity_id}"
  managed_image_name                = "${var.managed_image_name}"
  managed_image_resource_group_name = "${var.managed_image_rg}"
  os_disk_size_gb                   = 128
  os_type                           = "Windows"
  security_group_name               = "${var.nsg_name}"
  subnet_id                         = "${var.subnet_id}"
  subscription_id                   = "Free Trial"
  virtual_network_name              = "${var.vnet_name}"
  vm_size                           = "Standard_DS2_v2"
  winrm_insecure                    = true
  winrm_timeout                     = "1h"
  winrm_use_ssl                     = true
}

build {
  sources = ["source.azure-arm.autogenerated_1"]

}

for this Im getting this error
PS C:\Users\ashwi\Packer> packer validate test.json.pkr.hcl
Error: Unsupported argument

on test.json.pkr.hcl line 49:
(source code not available)

An argument named “subnet_id” is not expected here.

Error: Unsupported argument

on test.json.pkr.hcl line 41:
(source code not available)

An argument named “base_image_id” is not expected here.

Error: Unsupported argument

on test.json.pkr.hcl line 48:
(source code not available)

An argument named “security_group_name” is not expected here.

Error: Unsupported argument

on test.json.pkr.hcl line 43:
(source code not available)

An argument named “managed_identity_resource_id” is not expected here.

Now I’m beginning to understand the issue.
Where did you find these four arguments?

I created those in portal and trying to give them in is something wrong. please let me know what is wrong and if these are not valid arguments i have one more packer script without all these i’ll add it but the issue im getting on that is Winrm timeout i have no NSG connected nor any firewall rules still i get that error

Those arguments are not present in the Builder documentation for Azure ARM.
You might have been trying to switch from one builder to another, or they’ve been removed after an plugin update, though I can’t find any builder or version that uses those arguments.
Each builder uses a different set of arguments.


variable "custom_data_file" {
  type    = string
  default = "/home/retro/Test.ps1"
}

variable "managed_image_name" {
  type    = string
  default = "my-test-image"
}

variable "managed_image_rg" {
  type    = string
  default = "Test_Image"
}

variable "vnet_name" {
  type    = string
  default = "Test_Vnet"
}

source "azure-arm" "autogenerated_1" {
  azure_tags = {
    dept = "Test"
  }
  client_id                           = "a4171f6a-993a-4759-995b-cee9d3b1c83b"
  client_secret                       = "rJW8Q~X3zhDx7QH0Q0FMIRCp~4-nUAmM0Pfv0dfN"
  communicator                        = "winrm"
  custom_data_file                    = "${var.custom_data_file}"
  image_offer                         = "Windows-11"
  image_publisher                     = "MicrosoftWindowsDesktop"
  image_sku                           = "win11-21h2-avd"
  location                            = "eastus"
  managed_image_name                  = "${var.managed_image_name}"
  managed_image_resource_group_name   = "${var.managed_image_rg}"
  os_disk_size_gb                     = 128
  os_type                             = "Windows"
  subscription_id                     = "66118adc-b709-4533-a6be-252b2f04211e"
  tenant_id                           = "43c8605a-15cd-4d10-b213-31a5373d3999"
  virtual_network_name                = "${var.vnet_name}"
  virtual_network_resource_group_name = "Test_Image"
  virtual_network_subnet_name         = "default"
  vm_size                             = "Standard_DS2_v2"
  winrm_insecure                      = true
  winrm_password                      = "Password"
  winrm_timeout                       = "1h"
  winrm_use_ssl                       = true
  winrm_username                      = "Username"
}

build {
  sources = ["source.azure-arm.autogenerated_1"]

}

So here im getting winrm timeout can you help me with this so the context is im running my packer script through azure cloud shell and the vm that creates the image is only created after i run the script and it is deleted once the process fails or completed so can you help me on why this winrm timeout is happening ?

Got it thanks for the doc and could you also help me out with WinRM timeout issue ?

I don’t use the same builder as you do, which uses a boot_command argument to create a user and password in the liveVM.
Once the boot_command or bootstrap script is done, a SSH or winRM connection is tried and if successful, the provisioners are loaded.

When an ssh or winrm timeout happens, your winrm_username and/or password are incorrect. This is often due to the liveVM not having them created, at least, that’s in my case. I don’t know if Windows has a default user or something.

Reading the documentation I would first try adding this → pause_before_connecting

The documentation talks about a bootstrap script, which I would argue is similar to the Qemu(Linux) boot_command argument that I use, but it’s unclear to me how such a bootstrap script is loaded for azure-arm.

I suspect instead of a boot_command, azure uses a user_data_filedocumentation