Featured image of post Packer with Windows Images and Chocolatey

Packer with Windows Images and Chocolatey

🍫 More Packer Magic: Windows Images and Chocolatey Goodness

So you read Packer in a Nutshell and you’re feeling spicy.
So now you used Packer to build a sleek little Linux image with Nginx, tossed it in AWS, and you’re high-fiving yourself.

But now your boss walks in and says:

“Hey, can you do this for a Windows Server image, with Chocolatey installed and pre-configured?”

Yes we can!

⚙️ What You’ll Need

Before we go full Windows wizardry, make sure you’ve got:

  • Packer installed
  • Access to AWS (or another builder platform)
  • A base Windows AMI (e.g., Windows Server 2019)
  • RDP access for testing (because SSH ain’t gonna cut it)
  • 🍫 A deep love for Chocolatey

🪟 Example: Packer + Windows + Chocolatey on AWS

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# windows-choco.pkr.hcl

variable "aws_region" {
  default = "us-east-1"
}

source "amazon-ebs" "windows" {
  region             = var.aws_region
  source_ami_filter {
    filters = {
      name                = "Windows_Server-2019-English-Full-Base-*"
      virtualization-type = "hvm"
    }
    owners      = ["801119661308"] # Microsoft
    most_recent = true
  }
  instance_type      = "t3.medium"
  ami_name           = "windows-choco-{{timestamp}}"
  user_data_file     = "setup-choco.ps1"
  communicator       = "winrm"
  winrm_username     = "Administrator"
  winrm_insecure     = true
  winrm_use_ssl      = false
  winrm_timeout      = "10m"
}

build {
  sources = ["source.amazon-ebs.windows"]
}

💡 What’s Going On Here?

  • We use the official Windows Server 2019 base image.
  • user_data_file runs a PowerShell script to install Chocolatey.
  • We use WinRM for remote access, because Windows doesn’t speak SSH (it barely speaks English half the time).

🍫 Chocolatey Installer Script (setup-choco.ps1)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# setup-choco.ps1

# Disable IE Enhanced Security (because it breaks installs)
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap" -Name IEHarden -Value 0

# Download and install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

# Install some stuff via Chocolatey
choco install -y googlechrome notepadplusplus git

💥 That script installs:

  • Google Chrome (because IE is a cursed relic)
  • Notepad++ (for actual editing)
  • Git (because Git is life)

🔨 Build the Image

1
2
3
packer init .
packer validate windows-choco.pkr.hcl
packer build windows-choco.pkr.hcl

🧪 Testing It

Once it builds successfully, spin up an instance of your new image.

  • Use RDP to connect.
  • Login as Administrator.
  • Check that Chocolatey and all your apps are installed.
  • Bask in your glorious Windows DevOps power. ⚡

🧠 Extra Tips for Windows + Packer

TipWhy It Matters
Use t3.medium or largerWindows is thicc. Tiny instances will crawl.
Enable WinRM correctlyPacker needs to connect during provisioning.
Use user_data_file for boot-time scriptsEspecially useful when you need Chocolatey ready before anything else
Disable Windows Defender during buildIt can slow things down a lot (re-enable after if needed)
Snapshot your imagesStore your goldens safely and use them in Terraform

🤯 Bonus: Adding VS Code and Node.js

Just add to the PowerShell script:

1
choco install -y vscode nodejs

And boom. You’ve got a dev-ready Windows machine image baked, seasoned, and served.


🧑‍🍳 The Bake-Off Continues…

Packer isn’t just a Linux bro — it’s fully bilingual. You can use it to create reliable, repeatable Windows images, automate your dev environments, and even standardize your infrastructure across teams.

Chocolatey + Packer is like peanut butter + jelly — or maybe more like PowerShell + sanity, which is rare but beautiful.


🔑 Key Ideas

ConceptSummary
Packer supports WindowsFully works with WinRM and PowerShell
Chocolatey integrationInstall apps easily during image build
PowerShell provisioningScripts can do setup, install, and config
Use caseGreat for dev VMs, remote workers, CI test images
Extra toolsGit, Chrome, Notepad++, VSCode, Node.js, and more via Choco

🪄 Now go forth, build Windows images, and automate your life like it’s 2099.

Next up: Want to build Windows images locally with VirtualBox or pipe them into Vagrant? Stay tuned, it gets weirder (and cooler).


Click the button below to copy this full article into your notes or dev docs:

1
<!-- Copy this full markdown content block from here to your site or editor -->