<< All versions
Skill v1.0.1
currentAutomated scan100/100hashicorp/agent-skills/windows-builder
+2 new
──Details
PublishedAugust 18, 2026 at 12:34 AM
Content Hashsha256:0ddd0188747e826f...
Git SHA4451ceca5456
Bump Typepatch
──Files
Files (1 file, 4.5 KB)
SKILL.md4.5 KBactive
SKILL.md · 190 lines · 4.5 KB
version: "1.0.1" name: windows-builder description: Build Windows images with Packer using WinRM communicator and PowerShell provisioners. Use when creating Windows AMIs, Azure images, or VMware templates. metadata: lifecycle-status: active
Windows Builder
Platform-agnostic patterns for building Windows images with Packer.
Reference: WinRM Communicator
Note: Windows builds incur significant costs and time. Expect 45-120 minutes per build due to Windows Updates. Failed builds may leave resources running - always verify cleanup.
WinRM Communicator Setup
Windows requires WinRM for Packer communication.
AWS Example
hcl
source "amazon-ebs" "windows" {region = "us-west-2"instance_type = "t3.medium"source_ami_filter {filters = {name = "Windows_Server-2022-English-Full-Base-*"}most_recent = trueowners = ["amazon"]}ami_name = "windows-server-2022-${local.timestamp}"communicator = "winrm"winrm_username = "Administrator"winrm_use_ssl = truewinrm_insecure = truewinrm_timeout = "15m"user_data_file = "scripts/setup-winrm.ps1"}
WinRM Setup Script (scripts/setup-winrm.ps1)
powershell
<powershell># Configure WinRMwinrm quickconfig -qwinrm set winrm/config '@{MaxTimeoutms="1800000"}'winrm set winrm/config/service '@{AllowUnencrypted="true"}'winrm set winrm/config/service/auth '@{Basic="true"}'# Configure firewallnetsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allownetsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow# Restart WinRMnet stop winrmnet start winrm</powershell>
Azure Example
hcl
source "azure-arm" "windows" {client_id = var.client_idclient_secret = var.client_secretsubscription_id = var.subscription_idtenant_id = var.tenant_idmanaged_image_resource_group_name = "images-rg"managed_image_name = "windows-${local.timestamp}"os_type = "Windows"image_publisher = "MicrosoftWindowsServer"image_offer = "WindowsServer"image_sku = "2022-datacenter-g2"location = "East US"vm_size = "Standard_D2s_v3"# Azure auto-configures WinRMcommunicator = "winrm"winrm_use_ssl = truewinrm_insecure = truewinrm_timeout = "15m"winrm_username = "packer"}
PowerShell Provisioners
Install Software
hcl
build {sources = ["source.amazon-ebs.windows"]# Install Chocolateyprovisioner "powershell" {inline = ["Set-ExecutionPolicy Bypass -Scope Process -Force","iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"]}# Install applicationsprovisioner "powershell" {inline = ["choco install -y googlechrome","choco install -y 7zip",]}# Install IISprovisioner "powershell" {inline = ["Install-WindowsFeature -Name Web-Server -IncludeManagementTools"]}}
Windows Updates
hcl
provisioner "powershell" {inline = ["Install-PackageProvider -Name NuGet -Force","Install-Module -Name PSWindowsUpdate -Force","Import-Module PSWindowsUpdate","Get-WindowsUpdate -Install -AcceptAll -AutoReboot",]timeout = "2h"}# Wait for rebootsprovisioner "windows-restart" {restart_timeout = "30m"}
Cleanup
hcl
provisioner "powershell" {inline = ["# Clear temp files","Remove-Item -Path 'C:\\Windows\\Temp\\*' -Recurse -Force -ErrorAction SilentlyContinue","# Clear Windows Update cache","Stop-Service -Name wuauserv -Force","Remove-Item -Path 'C:\\Windows\\SoftwareDistribution\\*' -Recurse -Force -ErrorAction SilentlyContinue","Start-Service -Name wuauserv",]}
Common Issues
WinRM Timeout
- Increase
winrm_timeoutto 15m or more - Verify security group allows ports 5985/5986
- Check user data script completed successfully
PowerShell Execution Policy
hcl
provisioner "powershell" {inline = ["Set-ExecutionPolicy Bypass -Scope Process -Force","# Your commands here",]}
Long Build Times
- Windows Updates can take 1-2 hours
- Use pre-patched base images when available
- Set provisioner
timeout = "2h"