High-Level Steps #
Infrastructure: #
- A Virtual Machine with a Managed Identity
- Created the VM, an Public IP, an NSG/ASG to allow RDP
- A Resource Group for that Virtual Machine
- A Resource Group that Packer can use to create VMs
- A Resource Group where the Managed Images or VHD files are stored
- (opt) A storage account to store the vhd files
Packer Configuration #
- Connect to VM (RDP)
- 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'))
- Choco Install Packer
choco install packer
- (opt) Install vscode
choco install vscode
mkdir C:\Packer
- verify packer is installed
packer -v
- Create configuration file, windows-desktop.pkr.hcl
packer {
required_plugins {
azure = {
version = ">= 1.3.0"
source = "github.com/hashicorp/azure"
}
}
}
- 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.