Created
June 29, 2018 06:21
-
-
Save rezamt/723c55755cc911d19cbcd77029406d02 to your computer and use it in GitHub Desktop.
Packager Building Image for Windows - using azure-arm builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"variables": { | |
"client_id": "{{env `AZURE_CLIENT_ID`}}", | |
"client_secret": "{{env `AZURE_CLIENT_SECRET`}}", | |
"subscription_id": "{{env `AZURE_SUBSCRIPTION_ID`}}", | |
"tenant_id": "{{env `AZURE_TENANT_ID`}}", | |
"spn_object_id": "{{env `AZURE_SPN_OBJECT_ID`}}", | |
"resource_group": "{{env `AZURE_BUILD_RESOURCE_GROUP`}}", | |
"resource_location": "{{env `AZURE_BUILD_LOCATION`}}", | |
"storage_account": "{{env `AZURE_BUILD_STORAGE_ACCOUNT`}}", | |
"vm_size": "{{env `AZURE_DEFAULT_VM_SIZE`}}", | |
"image_os_sku": "2016-Datacenter-Server-Core" | |
}, | |
"builders": [{ | |
"type": "azure-arm", | |
"client_id": "{{user `client_id`}}", | |
"client_secret": "{{user `client_secret`}}", | |
"subscription_id": "{{user `subscription_id`}}", | |
"tenant_id": "{{user `tenant_id`}}", | |
"object_id": "{{user `spn_object_id`}}", | |
"managed_image_name": "{{user `image_os_sku`}}--{{isotime \"2006.01.02-1504\"}}", | |
"managed_image_resource_group_name": "{{user `resource_group`}}", | |
"managed_image_storage_account_type": "Premium_LRS", | |
"os_type": "Windows", | |
"image_publisher": "MicrosoftWindowsServer", | |
"image_offer": "WindowsServer", | |
"image_sku": "{{user `image_os_sku`}}", | |
"communicator": "winrm", | |
"winrm_use_ssl": "true", | |
"winrm_insecure": "true", | |
"winrm_timeout": "5m", | |
"winrm_username": "packer", | |
"location": "{{user `resource_location`}}", | |
"vm_size": "{{user `vm_size`}}" | |
}], | |
"provisioners": [ | |
{ | |
"type": "windows-shell", | |
"inline": [ | |
"powershell.exe -ExecutionPolicy bypass -windowstyle hidden -Command $PSVersionTable", | |
"systeminfo" | |
] | |
}, | |
{ | |
"type": "powershell", | |
"inline": [ | |
"(gcim win32_service | ? { $_.name -match 'WindowsAzureGuestAgent' }).PathName", | |
"get-service WindowsAzureGuestAgent | ft -autosize" | |
] | |
}, | |
{ | |
"type": "powershell", | |
"inline": [ | |
"if( Test-Path $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml ){ rm $Env:SystemRoot\\windows\\system32\\Sysprep\\unattend.xml -Force}", | |
"& $Env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quit /quiet", | |
"while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment