hashicorp / packer-plugin-amazon

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

Fix spot instance launch readiness #308

Closed sparrc closed 1 year ago

sparrc commented 1 year ago

When launching ec2 source instances, we have code which waits for the instance to become ready, but previously this codepath was not being applied to spot instances.

This change factors that code out into a common function, and then calls that common function in both the 'regular' and 'spot' instance launches.

This fixes issues where packer tries to connect to a spot instance before it is running and ready, which means it won't have a public ip address ready yet, and so packer times out on SSH access.

fixes #40

hashicorp-cla commented 1 year ago

CLA assistant check
All committers have signed the CLA.

sparrc commented 1 year ago

Thanks for the review, I will take a look at that, I think I should be able to fix it

sparrc commented 1 year ago

Updated to PR to use ec2iface.EC2API down into WaitUntilInstanceRunning, thanks again for the review @lbajolet-hashicorp !

sparrc commented 1 year ago

Now it seems like the mocks are panicking when ec2conn.WaitUntilInstanceRunningWithContext is called. Not exactly sure why that is though? Do the mocks need to be regenerated?

edit: from what I could tell the runSpotEC2ConnMock struct was not autogenerated, so I added the mock WaitUntilInstanceRunningWithContext function manually, let me know if that looks OK!