Creating Packer Windows Image in GCP but facing WinRM timeout error and image creation is failing. Require help on the below issue.
Below is the Packer file.
packer {
required_plugins {
googlecompute = {
version = ">= 0.0.1"
source = "github.com/hashicorp/googlecompute"
}
}
}
variable "region" {
type = string
default = "asia-south1-a"
}
variable "winrm_password" {
type = string
sensitive = true
description = "WinRM user password"
default = "SuperSecr3t!!!!"
}
variable "skip_create_image" {
type = bool
description = "To skip AMI creation, helpful in testing"
default = false
}
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
# source blocks are generated from your builders; a source can be referenced in
# build blocks. A build block runs provisioner and post-processors on a
# source.
source "googlecompute" "google-windows" {
project_id = "mt5-loadtesting"
source_image = "windows-server-2019-dc-v20200813"
machine_type = "n1-standard-2"
zone = "${var.region}"
#skip_create_image = "${var.skip_create_image}"
disk_size = "50"
user_data_file = "./Bootstrap/bootstrap_win.txt"
winrm_password = "${var.winrm_password}"
winrm_username = "packer_user"
metadata = {
#windows-startup-script-cmd = "winrm quickconfig -quiet & winrm set winrm/config/service/auth @{Basic=\"true\"}"
windows-startup-script-cmd = "winrm quickconfig -quiet & net user /add packer_user & net localgroup administrators packer_user /add & net user packer_user ${var.winrm_password} & winrm set winrm/config/service/auth @{Basic=\"true\"}"
}
}
# a build block invokes sources and runs provisioning steps on them.
build {
name = "learn-packer"
sources = ["source.googlecompute.google-windows"]
provisioner "windows-shell" {
inline = [
"Write-Host \"Testing GCP\""
]
}
# Running test PowerShell Script
provisioner "powershell" {
script = "./PowerShell/test.ps1"
}
}