hashicorp / packer-plugin-amazon

Packer plugin for Amazon AMI Builder
https://www.packer.io/docs/builders/amazon
Mozilla Public License 2.0
72 stars 110 forks source link

WinRM I/O timeout during packer build when using private subnet #190

Open hc-github-team-packer opened 2 years ago

hc-github-team-packer commented 2 years ago

This issue was originally opened by @JrInfra in https://github.com/hashicorp/packer/issues/11444 and has been migrated to this repository. The original issue description is below.


Overview of the Issue

I'm trying to create an AWS AMI with packer but it seems like I am running into an issue where it seems WinRM keeps timing out when I use a private subnet.

I've taken a look and can see there is a IGW attached to the VPC and when I do try this with a public subnet, its able to connect to WinRM just fine with no issues.

My question is what can be stopping winRM from connecting and how to prevent timeouts from occurring?

Reproduction Steps:

Launch the template and attempt to create AMI (packer build .)

Packer version

1.7.8

Simplified Packer Template:

`packer { required_plugins { amazon = { version = ">= 0.0.2" source = "github.com/hashicorp/amazon" } } }

source "amazon-ebs" "windows_server" { ami_description = "TestAMI" ami_name = "TestAMI" ami_users = ["${var.ami_users}"] associate_public_ip_address = false communicator = "winrm" instance_type = "${var.instance_type}" region = "${var.aws_region}" security_group_id = "${var.security_group_id}" force_deregister = true force_delete_snapshot = true source_ami_filter { filters = { architecture = "x86_64" name = "Windows_Server-2019-English-Full-ContainersLatest-*" root-device-type = "ebs" virtualization-type = "hvm" } most_recent = true owners = ["amazon"] } subnet_id = "${var.subnet_id}" user_data_file = "./bootstrap_windows.txt" vpc_id = "${var.vpc_id}" winrm_insecure = true winrm_port = 5986 winrm_use_ssl = true winrm_timeout = "60m" winrm_username = "Administrator" }

build { sources = ["source.amazon-ebs.windows_server"]

provisioner "powershell" { script = "./SetNetwork.ps1"

]

}

}`

Operating system:

The EC2 is Windows Server 2019

Packerlog output:

2021/12/13 09:02:59 Using host value: EC2InstancePrivateIP 2021/12/13 09:02:59 packer-plugin-amazon_v1.0.1_x5.0_linux_amd64 plugin: 2021/12/13 09:02:59 [INFO] Attempting WinRM connection... 2021/12/13 09:02:59 packer-plugin-amazon_v1.0.1_x5.0_linux_amd64 plugin: 2021/12/13 09:02:59 [DEBUG] connecting to remote shell using WinRM 2021/12/13 09:03:29 packer-plugin-amazon_v1.0.1_x5.0_linux_amd64 plugin: 2021/12/13 09:03:29 [ERROR] connection error: unknown error Post "EC2InstancePrivateIP:5986/wsman": dial tcp EC2InstancePrivateIP:5986: i/o timeout 2021/12/13 09:03:29 packer-plugin-amazon_v1.0.1_x5.0_linux_amd64 plugin: 2021/12/13 09:03:29 [ERROR] WinRM connection err: unknown error Post "EC2InstancePrivateIP:5986/wsman": dial tcp EC2InstancePrivateIP:5986: i/o timeout

itsrahul-cdw commented 1 year ago

Hi Team,

Is there any update on this. I'm also facing the same issue with both AWS Windows and Linux Ubuntu Images. They'are working fine on WinRM and SSH communicator if using public subnet. But getting below timeout exception:

==> ubuntu-amazon-ebs.ubuntu: Waiting for SSH to become available... ==> ubuntu-amazon-ebs.ubuntu: Timeout waiting for SSH.

I've already used below configuration but those are meant for using the private IP instead of the public one in public subnet:

associate_public_ip_address = false ssh_interface = "private_ip"

Please suggest.

henrykie commented 4 months ago

Any update on this?