minimal-windows-server.json

{
  "provisioners": [
    {
        "type": "powershell",
        "scripts": [
            "{{ template_dir }}/scripts/Windows/create_appveyor_user.ps1"
        ],
        "environment_vars": [
            "appveyor_user={{user `install_user`}}",
            "appveyor_password={{user `install_password`}}"
        ]
    },
    {
        "type": "powershell",
        "inline":[
            "Write-Host \"Current user: $(whoami)\""
        ],
        "elevated_user": "{{user `install_user`}}",
        "elevated_password": "{{user `install_password`}}"
    },
    {
        "type": "powershell",
        "scripts":[
            "{{ template_dir }}/scripts/Windows/init_server.ps1"
        ],
        "elevated_user": "{{user `install_user`}}",
        "elevated_password": "{{user `install_password`}}"
    },
    {
        "type": "windows-restart",
        "restart_timeout": "30m"
    },
    {
        "type": "powershell",
        "scripts":[
            "{{ template_dir }}/scripts/Windows/install_path_utils.ps1",
            "{{ template_dir }}/scripts/Windows/install_powershell_core.ps1",
            "{{ template_dir }}/scripts/Windows/install_powershell_get.ps1",
            "{{ template_dir }}/scripts/Windows/install_7zip.ps1",
            "{{ template_dir }}/scripts/Windows/install_chocolatey.ps1",
            "{{ template_dir }}/scripts/Windows/install_nuget.ps1",
            "{{ template_dir }}/scripts/Windows/install_pstools.ps1"
        ],
        "elevated_user": "{{user `install_user`}}",
        "elevated_password": "{{user `install_password`}}"
    },
    {
        "type": "powershell",
        "scripts":[
            "{{ template_dir }}/scripts/Windows/install_git.ps1",
            "{{ template_dir }}/scripts/Windows/install_git_lfs.ps1",
            "{{ template_dir }}/scripts/Windows/install_mercurial.ps1",
            "{{ template_dir }}/scripts/Windows/install_subversion.ps1",
            "{{ template_dir }}/scripts/Windows/add_ssh_known_hosts.ps1"
        ],
        "elevated_user": "{{user `install_user`}}",
        "elevated_password": "{{user `install_password`}}"
    },
    {
        "type": "powershell",
        "scripts":[
            "{{ template_dir }}/scripts/Windows/install_appveyor_build_agent_core.ps1",
            "{{ template_dir }}/scripts/Windows/enable_autologon.ps1"
        ],
        "environment_vars": [
            "appveyor_user={{user `install_user`}}",
            "appveyor_password={{user `install_password`}}",
            "build_agent_mode={{user `build_agent_mode`}}"
        ],
        "elevated_user": "{{user `install_user`}}",
        "elevated_password": "{{user `install_password`}}"
    },
    {
    "type": "powershell",
    "inline": [
        "C:/ProgramData/Amazon/EC2-Windows/Launch/Scripts/InitializeInstance.ps1 -Schedule"
    ],
    "only": ["amazon-ebs"]
    }
  ],
  "builders": [
    {
        "type": "azure-arm",
        "subscription_id": "{{ user `azure_subscription_id` }}",
        "client_id": "{{ user `azure_client_id` }}",
        "client_secret": "{{ user `azure_client_secret` }}",
        "location": "{{ user `azure_location` }}",

        "temp_resource_group_name": "packer-RG-win-{{uuid}}",

        "os_type": "Windows",
        "image_publisher": "MicrosoftWindowsServer",
        "image_offer": "WindowsServer",
        "image_sku": "2019-Datacenter",
        "vm_size": "{{user `azure_vm_size`}}",
        "os_disk_size_gb": 128,

        "capture_container_name": "appveyor-images-win",
        "capture_name_prefix": "win-{{user `datemark`}}",
        "resource_group_name": "{{ user `azure_resource_group_name` }}",
        "storage_account": "{{ user `azure_storage_account` }}",

        "communicator": "winrm",
        "winrm_use_ssl": "true",
        "winrm_insecure": "true",
        "winrm_timeout": "30m",
        "winrm_username": "packer",

        "azure_tags": {
          "automation": "packer",
          "OS": "WindowsServer 2019-Datacenter",
          "description": "{{user `image_description`}}",
          "date": "{{user `datemark`}}"
        }
    },
    {
      "type": "amazon-ebs",
      "access_key": "{{user `aws_access_key`}}",
      "secret_key": "{{user `aws_secret_key`}}",
      "region": "{{user `aws_region`}}",

      "source_ami_filter": {
        "filters": {
        "virtualization-type": "hvm",
        "name": "Windows_Server-2019-English-Full-Base*",
        "root-device-type": "ebs"
        },
        "owners": ["801119661308"],
        "most_recent": true
      },
      "instance_type": "{{user `aws_instance_type`}}",

      "communicator": "winrm",
      "winrm_username": "Administrator",
      "winrm_use_ssl": true,
      "winrm_insecure": true,
      "user_data_file":"{{ template_dir }}/scripts/Windows/ec2-userdata.ps1",

      "ami_name": "Appveyor Worker Windows Server 2019 {{uuid}}",
      "ami_description": "{{user `image_description`}}",
      "launch_block_device_mappings": [
        {
          "device_name": "/dev/sda1",
          "volume_size": 128,
          "volume_type": "gp2",
          "delete_on_termination": true
        }
      ]
    },
    {
      "type": "googlecompute",
      "account_file": "{{user `gce_account_file`}}",
      "project_id": "{{ user `gce_project` }}",
      "zone": "{{ user `gce_zone` }}",
      "source_image_family": "windows-2019",
      "state_timeout" : "15m",
      "machine_type": "{{ user `gce_machine_type` }}",
      "communicator": "winrm",
      "winrm_username": "packer_user",
      "winrm_insecure": true,
      "winrm_use_ssl": true,
      "instance_name": "windows-server-2019-{{uuid}}",
      "image_name": "windows-server-2019-{{timestamp}}",
      "image_description": "{{ user `image_description` }}",
      "disk_size": 200,
      "metadata": {
        "windows-startup-script-cmd": "winrm quickconfig -quiet & net user /add packer_user & net localgroup administrators packer_user /add & winrm set winrm/config/service/auth @{Basic=\"true\"}"
      }
    },
    {
      "type": "hyperv-iso",
      "boot_wait": "0s",
      "boot_command": [
        "<esc>",
        "<enter>",
        "<enter>"
      ],
      "communicator": "winrm",
      "cpus": 2,
      "disk_size": "{{user `disk_size`}}",
      "enable_secure_boot": true,
      "enable_virtualization_extensions": true,
      "generation": 2,
      "secondary_iso_images": [
        "{{ template_dir }}/iso/minimal-windows-server.iso"
      ],
      "guest_additions_mode": "disable",
      "iso_checksum": "{{user `iso_checksum`}}",
      "iso_checksum_type": "{{user `iso_checksum_type`}}",
      "iso_url": "{{user `iso_url`}}",
      "memory": 4096,
      "shutdown_command": "e:/shutdown_vm.bat",
      "output_directory": "{{user `output_directory`}}",
      "switch_name": "{{user `hyperv_switchname`}}",
      "vm_name": "windows-server-2019-{{user `datemark`}}",
      "winrm_timeout": "2h",
      "winrm_password": "{{user `install_password`}}",
      "winrm_username": "{{user `install_user`}}"
    }
    
  ],
  "post-processors": [
    {
      "type": "manifest",
      "output": "{{user `packer_manifest`}}",
      "strip_path": true
    }
  ]
}