First time using Packer and have not worked a lot with Windows. Have faced this issue now for a few weeks.
Trying to build a Windows AMI in AWS. The EC2 gets created, but never the AMI.
Using Packer Version 1.11.2 with packer-plugin-amazon_v1.3.4_x5.0. When running packer build, continue to get the following errors:
[INFO] Attempting WinRM connection...
[DEBUG] connecting to remote shell using WinRM
[ERROR] connection error: unknown error Post "http://172.XX.XX.XX:5985/wsman": dial tcp 172.XX.XX.XX:5985: i/o timeout
[ERROR] WinRM connection err: unknown err: unknown error Post "http://172.XX.XX.XX:5985: i/o timeout
Here is my packer file:
packer {
required_version = ">=1.10.0"
required_plugins {
amazon = {
version = ">=1.3.3"
source = "github.com/hashicorp/amazon"
}
}
variable "ami_name" {
type = string
description = "Name of AMI to Create"
default = "packer-windows-server-2019"
}
variable "instance_type" {
type = string
description = "Name of EC2 Instance Class"
default = "g4dn.xlarge"
}
variable "region" {
type = string
description = "Name of AWS Region"
default = "us-gov-east-1"
}
variable "vpc_id" {
type = string
description = "Name of VPC"
default ="vpc-0083ef03ea83cb"
}
variable "subnet_id"
type = string
description = "Name of Subnet"
default = "subnet-82af8210bc83d083132"
}
variable "key_name" {
type = string
description = "Name of Keypair"
default = "scrubbed"
}
variable "sourced_ami" {
type = string
description = "AMI Being Used"
default = "ami-382ddee9381342acf"
}
variable "winrm_username"
type = string
description ="the username used to connect to the instance via WinRM"
default "Administrator"
}
variable "winrm_password"
type = string
description = "Password for EC2"
default = "SuperSecretSquirrlPa$$w@0rd"
sensitive = true
}
source "amazon-ebs" "packer-generated-v1" {
iam_instance_profile "Role_Goes_Here"
source_ami = "${var.source_ami}"
region = "${var.region}"
instance_type = "${var.instance_type}"
ami_name = WinServer_g4dn"
subnet_id = "${var.subnet_id}"
vpc_id = "${var.vpc_id}"
security_group_ids = ["sg-3381adf83a1231"]
communicator = "wimrm"
winrm_username ="${var.winrm_username}"
winrm_password = "${var.winrm_password}"
max_retires = 5
windows_password_timeout = "15m"
pause_before_connecting = "20m"
tags = {
Name = "${var.ami_name}"
}
}
build {
description = Win Serv 2019 g4dn"
sources = ["source.amazon-ebs.packer-generated-v1"]
provisioner "shell" {
inline = [
"powershell.exe -Command \"Install-WindowsFeatures -Name IIS -IncludeManagementTools\""<
"powershell.exec -Command \"iisreset\"",
]
}
}
A few notes.
I’ve set debugging, and only seeing the i/o timeout error.
Also the SG inbound rules, I have open to port 5985, 5986 and 3389.
I’ve tried to ping from the Packer EC2 and unable to ping and tried to use Netcat on the ports 5985, 5986 and 3389 and just get a TIMEOUT error.
I feel that my Packer file has a few settings missing and once getting these fixed, it will work.