Skip to main content

·206 words·1 min

High-Level Steps #

Infrastructure: #

  1. A Virtual Machine with a Managed Identity
    1. Created the VM, an Public IP, an NSG/ASG to allow RDP
  2. A Resource Group for that Virtual Machine
  3. A Resource Group that Packer can use to create VMs
  4. A Resource Group where the Managed Images or VHD files are stored
  5. (opt) A storage account to store the vhd files

Packer Configuration #

  1. Connect to VM (RDP)
  2. Install Choco
Set-ExecutionPolicy Bypass -Scope Process
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  1. Choco Install Packer choco install packer
  2. (opt) Install vscode choco install vscode
  3. mkdir C:\Packer
  4. verify packer is installed packer -v
  5. Create configuration file, windows-desktop.pkr.hcl
packer {
  required_plugins {
    azure = {
      version = ">= 1.3.0"
      source  = "github.com/hashicorp/azure"
    }
  }
}
  1. Packer commands:
packer init [config-file.pkr.hcl]
packer fmt .
packer validate [config-file.pkr.hcl]
packer build [config-file.pkr.hcl]

Additional Notes #

Be mindful of slashes in scripts. Packer recommends using forward-slash ‘/’ characters instead of backslashes ‘' in paths. This works for the most part but it caused one part of my configuration to fail when I was passing a path to a file as an input variable. Where necessary you can use double backslashes, where the first is an escape character.

Related

Terraform - Azure Managed Disks with For Each
·1204 words·6 mins
We have a use case with Azure where we want to support the ability to add, remove or resize additional data disks on a VM.