diff --git a/builder/amazon/common/step_key_pair.go b/builder/amazon/common/step_key_pair.go index a94adb01a..68ce5af2d 100644 --- a/builder/amazon/common/step_key_pair.go +++ b/builder/amazon/common/step_key_pair.go @@ -19,7 +19,6 @@ type StepKeyPair struct { KeyPairName string PrivateKeyFile string - keyName string doCleanup bool } @@ -68,12 +67,10 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } - // Set the keyname so we know to delete it later - s.keyName = s.TemporaryKeyPairName s.doCleanup = true // Set some state data for use in future steps - state.Put("keyPair", s.keyName) + state.Put("keyPair", s.TemporaryKeyPairName) state.Put("privateKey", *keyResp.KeyMaterial) // If we're in debug mode, output the private key to the working @@ -115,10 +112,10 @@ func (s *StepKeyPair) Cleanup(state multistep.StateBag) { // Remove the keypair ui.Say("Deleting temporary keypair...") - _, err := ec2conn.DeleteKeyPair(&ec2.DeleteKeyPairInput{KeyName: &s.keyName}) + _, err := ec2conn.DeleteKeyPair(&ec2.DeleteKeyPairInput{KeyName: &s.TemporaryKeyPairName}) if err != nil { ui.Error(fmt.Sprintf( - "Error cleaning up keypair. Please delete the key manually: %s", s.keyName)) + "Error cleaning up keypair. Please delete the key manually: %s", s.TemporaryKeyPairName)) } // Also remove the physical key if we're debugging. diff --git a/builder/openstack/step_key_pair.go b/builder/openstack/step_key_pair.go index b59052b6f..2d1500a5c 100644 --- a/builder/openstack/step_key_pair.go +++ b/builder/openstack/step_key_pair.go @@ -22,7 +22,6 @@ type StepKeyPair struct { KeyPairName string PrivateKeyFile string - keyName string doCleanup bool } @@ -85,7 +84,6 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction { } ui.Say(fmt.Sprintf("Created temporary keypair: %s", s.TemporaryKeyPairName)) - s.doCleanup = true keypair.PrivateKey = berToDer(keypair.PrivateKey, ui) @@ -115,11 +113,11 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction { } } - // Set the keyname so we know to delete it later - s.keyName = s.TemporaryKeyPairName + // we created a temporary key, so remember to clean it up + s.doCleanup = true // Set some state data for use in future steps - state.Put("keyPair", s.keyName) + state.Put("keyPair", s.TemporaryKeyPairName) state.Put("privateKey", keypair.PrivateKey) return multistep.ActionContinue @@ -185,7 +183,7 @@ func (s *StepKeyPair) Cleanup(state multistep.StateBag) { } ui.Say(fmt.Sprintf("Deleting temporary keypair: %s ...", s.TemporaryKeyPairName)) - err = keypairs.Delete(computeClient, s.keyName).ExtractErr() + err = keypairs.Delete(computeClient, s.TemporaryKeyPairName).ExtractErr() if err != nil { ui.Error(fmt.Sprintf( "Error cleaning up keypair. Please delete the key manually: %s", s.TemporaryKeyPairName))