= 1.0.0" source = "github.com/hashicorp/azure" } } } source "azure-arm" "example" { " /> = 1.0.0" source = "github.com/hashicorp/azure" } } } source "azure-arm" "example" { " /> = 1.0.0" source = "github.com/hashicorp/azure" } } } source "azure-arm" "example" { "/>

Argument block definition is required to set argument use the equals sign "=" to introduce the argument value

35 Views Asked by At

Here is the code:

packer 
  required_plugins {
    azure = {
      version = ">= 1.0.0"
      source  = "github.com/hashicorp/azure"
    }
  }
}

source "azure-arm" "example" {
  managed_image_name                 = "MT-Image"
  managed_image_resource_group_name  = cg

  location                           = eastus

  # Using Azure CLI for authentication
  use_azure_cli_auth = true

  image_offer     = "visualstudio2022"
  image_publisher = "microsoftvisualstudio"
  image_sku       = "20_04-lts-gen2"

  os_type         = "Windows"
  vm_size         = "Standard E2bds v5"
  os_disk_size_gb = 64

  shared_image_gallery_destination {
    resource_group       = cg
    gallery_name         = gallery1
    image_name           = "newimage"
    image_version        = "1.0.1"
    replication_regions  = ["eastus"]
    storage_account_type = "Standard_LRS"
  }
}

  build {
    sources = [
      "source.azure-arm.example"
    ]
  provisioner "powershell" {
    inline = ["Remove-WindowsFeature Web-Server", "while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit", "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10  } else { break } }"]
  }
} 

I tried to modify everything, please suggest the fix, thanks

I have prepared the HCL template to automate image creation in azure compute gallery using packer.

Please see the code above

1

There are 1 best solutions below

0
Marcin Słowikowski On

Syntax issue. The opening brace after the word "packer" is missing

packer {
  required_plugins {
    azure = {
      version = ">= 1.0.0"
      source  = "github.com/hashicorp/azure"
    }
  }
}

https://developer.hashicorp.com/packer/docs/templates/hcl_templates/blocks/packer#packer-block-syntax