I have an issue with running instance from custom image in Google Cloud Platform with Packer. After half of hour I got an issue WinRM timeout)
==> image-ami-win: Waiting for the instance to become running...
image-ami-win: Internal IP: 10.154.21.203
image-ami-win: IP: 10.154.21.203
==> image-ami-win: Using winrm communicator to connect: 10.154.21.203
==> image-ami-win: Waiting for WinRM to become available...
==> image-ami-win: Timeout waiting for WinRM.
==> image-ami-win: Deleting instance...
image-ami-win: Instance has been deleted!
==> image-ami-win: Deleting disk...
image-ami-win: Disk has been deleted!
Build 'image-ami-win' errored: Timeout waiting for WinRM.
If I use base Windows-2016 image - everything work in proper way.
{
"builders": [
{
"type": "googlecompute",
"account_file": "account.json",
"project_id": "my project",
"source_image_family": "windows-2016",
"image_family": "my-image"
"disk_size": "50",
"machine_type": "n1-standard-1",
"communicator": "winrm",
"winrm_username": "packer_user",
"winrm_insecure": true,
"winrm_use_ssl": true,
"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\"}"
},
"zone": "us-central1-a"
}
]
}
At first instead of packer_user I used "Administrator" username - it didn't work (Issue with using winrm user different from "packer_user" with Google Cloud Platform)
Currently, if I'm running instance from custom image (which was successfully created from windows-2016 gcp image) it showed me an error: "Build 'image-ami-win' errored: Timeout waiting for WinRM."
I don't run any custom provisioner which can influence on firewall or access. Just create instance from base windows-2016 image - shut down in, create image and build it with packer:
{
"variables": {
"zone": "us-east1-b",
"winrm_user" : "packer_user",
"builder_name": ""
},
"builders": [
{
"name": "image-ami-win",
"type": "googlecompute",
"project_id": "{{user `project_id`}}",
"zone": "{{user `zone`}}",
"source_image_family": "my-family"
"communicator": "winrm",
"winrm_username": "{{user `winrm_user`}}",
"image_name": "{{user `project`}}{{user `env`}}-{{build_name}}-{{user `team`}}-{{timestamp}}",
"machine_type": "n1-standard-4",
"disk_size": 50,
"network_project_id": "{{user `network_project_id`}}",
"subnetwork": "{{user `subnetwork`}}",
"omit_external_ip": false,
"use_internal_ip": false,
"tags": [
"project-{{user `project`}}",
"branch-{{user `branch`}}",
"commit-{{user `commit_id`}}",
],
"winrm_insecure": true,
"winrm_use_ssl": true,
"metadata": {
"windows-startup-script-cmd": "winrm quickconfig -quiet & net user /add {{user `winrm_user`}} & net localgroup administrators {{user `winrm_user`}} /add & winrm set winrm/config/service/auth @{Basic=\"true\"} & powershell -Command \"& {Set-ExecutionPolicy AllSigned -Force}\""
}
}
],
"provisioners": []
}
I've already tried to run start-up script:
<powershell>
Enter-PSSession -ComputerName server.domain.local -Credential domain\administrator
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 1
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
</powershell>
It hasn't helped for solving this issue. Also I can't connect through the RDP to this instance from Google Cloud Console (UI), but at the same time I can connect easily during creation an instance from Windows-2016 Google Cloud image.
Also I noticed difference between building instance from Google Cloud Windows-2016 image and custom image:
If I run instance from Windows-2016 Google Cloud Image I have next messages:
2019/10/21 12:22:38 packer: 2019/10/21 12:22:38 [INFO] Attempting WinRM connection...
2019/10/21 12:22:38 packer: 2019/10/21 12:22:38 [DEBUG] connecting to remote shell using WinRM
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [ERROR] connection error: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [ERROR] WinRM connection err: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [INFO] Attempting WinRM connection...
2019/10/21 12:23:08 packer: 2019/10/21 12:23:08 [DEBUG] connecting to remote shell using WinRM
2019/10/21 12:23:38 packer: 2019/10/21 12:23:38 [ERROR] connection error: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:38 packer: 2019/10/21 12:23:38 [ERROR] WinRM connection err: unknown error Post https://10.154.21.219:5986/wsman: dial tcp 10.154.21.219:5986: i/o timeout
2019/10/21 12:23:38 packer: 2019/10/21 12:23:38 [INFO] Attempting WinRM connection...
But if I run instance from custom image I have next messages:
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [INFO] Attempting WinRM connection...
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [DEBUG] connecting to remote shell using WinRM
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] connection error: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48984->10.154.21.203:5986: read: connection reset by peer
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] WinRM connection err: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48984->10.154.21.203:5986: read: connection reset by peer
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [INFO] Attempting WinRM connection...
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [DEBUG] connecting to remote shell using WinRM
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] connection error: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48988->10.154.21.203:5986: read: connection reset by peer
2019/10/21 10:46:08 packer: 2019/10/21 10:46:08 [ERROR] WinRM connection err: unknown error Post https://10.154.21.203:5986/wsman: read tcp 10.147.84.31:48988->10.154.21.203:5986: read: connection reset by peer
Differences in
/wsman: dial tcp 10.154.21.219:5986: i/o timeout
and
10.147.84.31:48988->10.154.21.203:5986: read:
. Looks like that some forwarding is working, but I don't understand why, because packer builder identical except image name.
Instance should be running successfully from custom image at the same way as I build instance from Google Cloud Windows-2016 base image.
I'm using Packer v. 1.4.4
Could someone, please help me with it?