{"id":19724534,"url":"https://github.com/andif888/packer-windows-azure","last_synced_at":"2026-05-11T01:41:54.425Z","repository":{"id":95852620,"uuid":"425664160","full_name":"andif888/packer-windows-azure","owner":"andif888","description":"This repository builds a Windows Master Image and publishes it to Azure Shared Image Gallery with a single run command. It nicely integrates Packer, Terraform and Ansible. Hook this thing into a real CI/CD pipeline and run it.","archived":false,"fork":false,"pushed_at":"2021-11-08T09:04:30.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-10T16:47:37.607Z","etag":null,"topics":["ansible","avd","azure-devops","azurerm","packer","terraform","wvd"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andif888.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-08T01:42:37.000Z","updated_at":"2024-06-25T11:30:44.000Z","dependencies_parsed_at":"2023-03-04T20:45:26.652Z","dependency_job_id":null,"html_url":"https://github.com/andif888/packer-windows-azure","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andif888%2Fpacker-windows-azure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andif888%2Fpacker-windows-azure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andif888%2Fpacker-windows-azure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andif888%2Fpacker-windows-azure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andif888","download_url":"https://codeload.github.com/andif888/packer-windows-azure/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241045688,"owners_count":19899700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","avd","azure-devops","azurerm","packer","terraform","wvd"],"created_at":"2024-11-11T23:26:09.403Z","updated_at":"2026-05-11T01:41:54.383Z","avatar_url":"https://github.com/andif888.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# packer-windows-azure\n\nThis repository builds Windows Master Images and publishes it to Azure Shared Image Gallery with a single [run command](./run.sh).\\\nIt nicely integrates [Packer](https://www.packer.io/downloads), [Terraform](https://www.terraform.io/downloads.html) and [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html). Hook this thing into a real CI/CD pipeline and run it.\n\nAn additional trick is: Variables from Terrafrom can be reused in Packer, because since Packer 1.5 \nHCL2 templates are supported and HCL2 is by the way the preferred way to write Packer configurations.\nThis is why there is a **shared_vars.hcl** file.\n\n**Terraform** is used to fulfill the pre-requesites in Azure.\n\nTerraform creates:\n\n- a resource group\n- a shared image gallery\n- a shared image definition\n\n**Packer** is used to build the windows master image from a Windows Marketplace image. \nPacker is also responsible for versioning the master image and placing it into the share image gallery. \n\nTo customize the master image, Packer runs **Ansible** and a specific [ansible playbook](./ansible/playbook.yml).\\\nThe ansible playbook is quite basic, but this is the place to do the real customization of you windows master image.\n\n## How to use this repo\n\n### Pre-requesites\n\nMake sure you have an azure service principal account. To create one you can use to following command in the azure command line tool. \nReplace your-azure-subscription-id with your real Scription ID. Feel free to also adjust the value of the `--name` attribute.\\\nOtherwise you can configure a service principal using the Azure Portal. Make sure it has `Contributor` role in your Azure subscription.\n\n```bash\n# Login\naz login\n\n# Create service principal with Contributor role\naz ad sp create-for-rbac \\\n--name=\"packer_sp\" \\\n--role=\"Contributor\" \\\n--scope=\"/subscriptions/your-azure-subscription-id\" \\\n--sdk-auth \\\n\u003e az_client_credentials.json\n```\n\n### Step 1: Adjust variables\n\nRename the file [shared_vars.hcl.sample](./shared_vars.hcl.sample) to `shared_vars.hcl` and adjust the variables for your Azure environment. \nDocumentation on each variable is inside the sample file.\n\n```bash\n# Rename the file\nmv shared_vars.hcl.sample shared_vars.hcl\n\n# Edit the file\nnano shared_vars.hcl\n```\n\n\nEspecially for each new run you should increment the version number in the variable `azure_shared_image_gallery_destination_image_version`.\\\nIf you do not increment the version, then an existing image-version gets overridden. \n\n### Step 2: Make sure to enter you own SSH Public Key into openssh.ps1\n\nEdit the file [./packer/setup/openssh.ps1](./packer/setup/openssh.ps1) and replace the existing SSH Public Key with your own.\nOtherwise I have access to your machines :-)\\\nThe relevant part is in **Line 24-27**.\n\n```powershell\n# Configure SSH public key\n$content = @\"\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDRYCV99Ge9LI5Y61t95pkcG7trsDyg/eAHLfTGDMHOGxPDdXSk7wW/OCNsKWeJV20wjayoti2JYB+u4FRvsuyccjRZPlRTsul67QOJEzXfORCHD4EYDTR45l0n08zkUPRfs70yo5L5YG9HYgVr6+EK/F8fFReFDvhZwy8LW/hJSeyVCWlbszmuQYcHRmCkWBeAgEiPqx0Mx17txjw9p4RK/LbweYxN4fGu5Nh2Dz9uSBi2IfGds3rPcQvjnJBzt2GEDoZXdXgwXl4T5B0xEDJVMqS/Q+gArcL82cGsY7zpoWpKfOuVy88GD1qaHZgMvQ3LQRyxVysfhxvzSXRX0eF8518/8hGNLxmSak3dZyi5J2ojPdaYzOxtn4JTDFUKNCBQNLHJZCBl1J7HvilTnwQDbgWm0UoFB0dWG3fX4u1wGm11L9sX0kzQ+NZH2Q+9HVX+1vJWZJuNjlhogcsmXG1hecLZPD7WFl82nbmN7zBQwHtUbjUNERMHvXuUvjPnkjJh0avZVtUCRupJhNgyhTR0cWpzffmA2nzdQpIn6z93zVrgefwIpfr+Grk/XQTOXisIfYz/3sofQ9a2hTdPTj0UwKzULB0Pvsf/aYvVEG7zC0sRfPG/pj5cGeFnOB3Ar2/jd58EB7mLzm45MZ+ztSNRW+Eg32Lq1WgOJZ15TiH/pQ== prianto_autodeploy_id_2018\n\"@ \n```\n\nIf you don't need SSH Public Key Authentication, you can remove the whole part between Line 24 and 40.\n\n### Step 3: Run\n\nRun the [run.sh](./run.sh).\n\n[run.sh](./run.sh) runs the [build.sh](./terraform/build.sh) in the [./terrform](./terraform) directory. \n\nAfter that it runs the [build.sh](./packer/build.sh) in the [./packer](./packer) directory.\n\n```bash\n./run.sh\n```\n\n----\n\n## Cleanup\n\nTo cleanup everything in azure, make sure to manually delete all image-versions in the share image gallery. `terraform destroy` is not able to delete the image-version, because the image-versions have been built by packer. \nAfter you have cleanup any image-version in the share image gallery you can use the following terraform command to destroy everything.\n\n```bash\n# cd into terraform directory\ncd ./terraform\n\n# run terraform destroy\nterraform destroy -var-file ../shared_vars.hcl\n```\n\n## Optional\n\n### Install Windows Updates during build\n\nYou can optionally install Windows Updates during the build operation. \nIf you would like this feature then you need to edit the [windows.pkr.hcl](./packer/windows.pkr.hcl) file before the build operation. Please uncomment the following sections:  \n  \nLine: 7-10\n```hcl\n    windows-update = {\n      version = \"0.14.0\"\n      source = \"github.com/rgl/windows-update\"\n    }\n```\nLine: 217-224\n```hcl\n  provisioner \"windows-update\" {\n    search_criteria = \"IsInstalled=0\"\n    filters = [\n      \"exclude:$_.Title -like '*Preview*'\",\n      \"include:$true\",\n    ]\n    update_limit = 25\n  }\n```\n\nIf running windows updates during build, then it sometimes makes sense to reboot the machine \nbefore doing addition configuration tasks using ansible. There is a commented `pre_tasks` \nin the [ansible playbook](./ansible/playbook.yml) to do exactly this.\\\nSimply uncomment the relevant **line 18-22**.\n\n```yaml\n  pre_tasks:\n    # If we have installed lots of windows update before running this playbook, then it makes sense to reboot first.\n    - name: Reboot first\n      win_reboot:\n        reboot_timeout: 3600\n        pre_reboot_delay: 10\n        post_reboot_delay: 30\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandif888%2Fpacker-windows-azure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandif888%2Fpacker-windows-azure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandif888%2Fpacker-windows-azure/lists"}