How hkaanturgut/automating-windows-vm-deployment-with-custom-packer-images-and-terraform-via-azure-devops-pipelines works
Project type and purpose
• This is an Infrastructure-as-Code (IaC) automation project that uses Packer to build custom Windows VM images and Terraform to deploy Azure infrastructure, all orchestrated via Azure DevOps CI/CD pipelines.
• Purpose: Automate creation of a “golden” Windows VM image with preinstalled tools (Git, VS Code, Terraform, Azure CLI) and then deploy Azure networking and VM resources based on that image.
File structure
• Top-level YAML pipelines:
• Packer-Golden-Image-Build.yml – defines the CI pipeline for building the custom image.
• Terraform-Packer-VM-Automation.yml – defines the CI pipeline for Terraform validations.
• Packer artifacts:
• golden-image-windows-2019.json & windows-variables.json – Packer build templates and variables.
• scripts/ – PowerShell provisioning scripts invoked by Packer (install-azcli, git, terraform, vscode, prepare-vm).
• Terraform/ – directory containing Terraform code, organized as modules:
• modules/image – references the custom image.
• modules/network_interface, network_security_group, subnet, public_ip, virtual_network, etc.
• modules/windows_virtual_machine – ties everything into the target VM.
• Terraform root configs: provider.tf, network.tf, windows-vm.tf, plus tfvars for dev and network.
README for additional insights
• Two CI pipelines with branch policies (one for Packer JSON changes, one for Terraform code).
• A CD (release) pipeline that runs Terraform Plan, awaits approval, then Terraform Apply.
a. Main components
1. Code Repository (Azure Repos/Git)
2. Azure DevOps Pipelines:
– CI Pipeline “Packer Build”
– CI Pipeline “Terraform Validate”
– CD Pipeline “Terraform Plan & Apply”
3. Packer Builder & Provisioners (JSON templates + scripts)
4. Terraform Engine & Modules
5. Azure Components:
– Storage Account (remote tfstate)
– Resource Group
– Virtual Network → Subnet → NSG → NIC → Public IP
– Windows VM (using the custom image)
6. Service Principal / Service Connection
b. Relationships & interactions
• CI Packer pipeline pulls Packer templates & scripts → builds image → publishes image to Azure.
• CI Terraform pipeline triggers on Terraform folder changes → runs plan/validate.
• CD pipeline fetches artifacts → Terraform Plan against remote state → manual approval → Terraform Apply → Azure resource creation.
• Service Principal credentials flow into both pipelines to authenticate with Azure.
c. Architectural patterns & principles
• Separation of concerns: Packer image build vs. Infrastructure deployment.
• Modular Terraform code (each Azure resource is a reusable module).
• Git-Ops style triggers: branch policies → pipelines.
• Immutable infrastructure: create golden image, then deploy VMs from it.
d. Key technologies & frameworks
• Azure DevOps Pipelines (YAML)
• HashiCorp Packer (azure-arm builder, PowerShell provisioners)
• HashiCorp Terraform (AzureRM provider, modules)
• Azure Resource Manager (for actual resource creation)
• PowerShell scripts for in-image software installation