From 9c0f37b2c99cca00fef568ad5af79796681ea654 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 19 Jun 2015 06:21:20 +0200 Subject: [PATCH] builder/amazon: fix weird edge cases with key names [GH-2281] --- builder/amazon/common/step_key_pair.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/builder/amazon/common/step_key_pair.go b/builder/amazon/common/step_key_pair.go index 5bed27b10..6e7f2bb2b 100644 --- a/builder/amazon/common/step_key_pair.go +++ b/builder/amazon/common/step_key_pair.go @@ -23,17 +23,14 @@ type StepKeyPair struct { func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction { if s.PrivateKeyFile != "" { - if s.KeyPairName != "" { - s.keyName = s.KeyPairName // need to get from config - } - privateKeyBytes, err := ioutil.ReadFile(s.PrivateKeyFile) if err != nil { - state.Put("error", fmt.Errorf("Error loading configured private key file: %s", err)) + state.Put("error", fmt.Errorf( + "Error loading configured private key file: %s", err)) return multistep.ActionHalt } - state.Put("keyPair", s.keyName) + state.Put("keyPair", s.KeyPairName) state.Put("privateKey", string(privateKeyBytes)) return multistep.ActionContinue @@ -43,7 +40,8 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) ui.Say(fmt.Sprintf("Creating temporary keypair: %s", s.TemporaryKeyPairName)) - keyResp, err := ec2conn.CreateKeyPair(&ec2.CreateKeyPairInput{KeyName: &s.KeyPairName}) + keyResp, err := ec2conn.CreateKeyPair(&ec2.CreateKeyPairInput{ + KeyName: &s.TemporaryKeyPairName}) if err != nil { state.Put("error", fmt.Errorf("Error creating temporary keypair: %s", err)) return multistep.ActionHalt