hashicorp / hashicorp/packer-plugin-amazon
disable_stop_instance = true breaks the Packer build, even with a sysprep/shutdown step
- Dominant language
- Go
- Stars
- 91
- Forks
- 141
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 3
Description
#### Overview of the Issue
After the Packer provisioners all complete, and the instance is being shut down, Packer waits only a very short amount of time (~1 minute max) before failing with the following error:
> Error waiting for instance to stop: ResourceNotReady: failed waiting for successful resource state
I am using `disable_stop_instance = true` because I am using a sysprep step as the final provisioner, which will shutdown the machine.
As far as I can tell, I'm not encrypting anything, so all the similar issues I've seen previously don't seem to apply, I'm not using any KMS keys or anything those lines.
#### Reproduction Steps
1. Run build.
2. Wait for it to finish provisioning
3. During shutdown sequence, packer fails to wait long enough (seemingly) and assumes things have failed
### Plugin and Packer version
Packer v1.7.4
### Simplified Packer Buildfile
build.pkr.hcl
```hcl
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
source "amazon-ebs" "default" {
access_key = "${var.aws_access_key}"
ami_name = "windows2019-sqlserver-${local.timestamp}"
communicator = "winrm"
disable_stop_instance = true
encrypt_boot = false
instance_type = "t2.medium"
launch_block_device_mappings {
delete_on_termination = true
device_name = "/dev/sda1"
volume_size = 64
encrypted = false
}
max_retries = 5
no_ephemeral = true
region = "us-east-1"
secret_key = "${var.aws_secret_key}"
shutdown_behavior = "terminate"
source_ami = "ami-03295ec1641924349"
aws_polling {
delay_seconds = 30
max_attempts = 80
}
}
build {
sources = ["source.amazon-ebs.default"]
# other provisioners here
provisioner "powershell" {
scripts = ["./setup/Install-Ec2Launch.ps1"]
}
provisioner "windows-restart" {
restart_check_command = "powershell -Command \"Write-Output 'Restart Complete'\""
restart_command = "powershell -Command \"Restart-Computer -Force\""
restart_timeout = "10m"
}
provisioner "windows-shell" {
inline = ["\"%programfiles%\\amazon\\ec2launch\\ec2launch.exe\" sysprep --shutdown=true"]
}
}
```
Install-Ec2Launch.ps1
```powershell
$downloadUrl = 'https://s3.amazonaws.com/amazon-ec2launch-v2/windows/amd64/latest/AmazonEC2Launch.msi'
$filePath = "$env:TEMP\AmazonEC2Launch.msi"
$ProgressPreference = 'SilentlyContinue'
Write-Host "Downloading EC2Launch MSI"
Invoke-WebRequest -Uri $downloadUrl -OutFile $filePath
$msiArgs = @(
'/i'
$filePath
'ADDLOCAL="Basic,Clean"'
'/q'
)
Write-Host "Installing EC2Launch"
msiexec @msiArgs
```
### Operating system and Environment details
Host OS: MacOS Big Sur 11.4
VM: Windows 2019 x64
### Log Fragments and crash.log files
Log fragment
```log
==> amazon-ebs.default: Provisioning with windows-shell...
==> amazon-ebs.default: Provisioning with shell script: /var/folders/_g/xzqnsbhx1fg_pcy3f15g6dh00000gn/T/windows-shell-provisioner052299118
amazon-ebs.default:
amazon-ebs.default: C:\Users\Administrator>"C:\Program Files\amazon\ec2launch\ec2launch.exe" sysprep --shutdown=true
amazon-ebs.default: 'sysprep' command running in blocking mode.
amazon-ebs.default: service is still running...checking again in '5.000000' seconds
==> amazon-ebs.default: 2021-07-23 13:19:40 Info: Preparing items to execute Sysprep
==> amazon-ebs.default: 2021-07-23 13:19:40 Console: Message: Successfully disabled hibernation
amazon-ebs.default: agent ran successfully
==> amazon-ebs.default: 2021-07-23 13:19:40 Info: Executing Sysprep
amazon-ebs.default: Sysprep sub-command: shutdown: true clean: false
==> amazon-ebs.default: 2021-07-23 13:19:40 Info: Sysprep command: C:\Windows\System32\Sysprep\Sysprep.exe /oobe /shutdown /generalize /unattend:C:\ProgramData\Amazon\EC2Launch\sysprep\unattend.xml
==> amazon-ebs.default: Automatic instance stop disabled. Please stop instance manually.
==> amazon-ebs.default: Waiting for the instance to stop...
==> amazon-ebs.default: Error waiting for instance to stop: ResourceNotReady: failed waiting for successful resource state
==> amazon-ebs.default: Provisioning step had errors: Running the cleanup provisioner, if present...
==> amazon-ebs.default: Terminating the source AWS instance...
==> amazon-ebs.default: Cleaning up any extra volumes...
==> amazon-ebs.default: No volumes to clean up, skipping
==> amazon-ebs.default: Deleting temporary keypair...
Build 'amazon-ebs.default' errored after 18 minutes 17 seconds: Error waiting for instance to stop: ResourceNotReady: failed waiting for successful resource state
```
Contributor guide
Assessment
This issue has not been assessed yet.