From f95514c1200e8b8244cdc06edb9106adbbfb5b1a Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Sun, 26 Feb 2017 17:17:49 -0800 Subject: [PATCH 1/2] fix ssh agent authentication treat key name to empty string if it's not been set by prior step. --- builder/amazon/common/step_run_source_instance.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index e9b1f5216..040cb351c 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -41,7 +41,10 @@ type StepRunSourceInstance struct { func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepAction { ec2conn := state.Get("ec2").(*ec2.EC2) - keyName := state.Get("keyPair").(string) + var keyName string + if name, ok := state.GetOk("keyPair"); ok { + keyName = name.(string) + } securityGroupIds := aws.StringSlice(state.Get("securityGroupIds").([]string)) ui := state.Get("ui").(packer.Ui) From 2cb9b32acfbaa45d862cd6877297f52c8098b25c Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Sun, 26 Feb 2017 17:38:22 -0800 Subject: [PATCH 2/2] don't attempt to delete non-existant key when using agent auth --- builder/amazon/common/step_key_pair.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/amazon/common/step_key_pair.go b/builder/amazon/common/step_key_pair.go index ed3890374..c5e3ff13a 100644 --- a/builder/amazon/common/step_key_pair.go +++ b/builder/amazon/common/step_key_pair.go @@ -107,7 +107,7 @@ func (s *StepKeyPair) Cleanup(state multistep.StateBag) { // If no key name is set, then we never created it, so just return // If we used an SSH private key file, do not go about deleting // keypairs - if s.PrivateKeyFile != "" || s.KeyPairName != "" { + if s.PrivateKeyFile != "" || (s.KeyPairName == "" && s.keyName == "") { return }