builder/amazon: set flag to delete temporary keypair
This commit is contained in:
parent
1ec9525204
commit
602fd64c5d
|
@ -20,6 +20,7 @@ type StepKeyPair struct {
|
|||
PrivateKeyFile string
|
||||
|
||||
keyName string
|
||||
doCleanup bool
|
||||
}
|
||||
|
||||
func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -69,6 +70,7 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
|||
|
||||
// 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)
|
||||
|
@ -104,10 +106,7 @@ func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
|||
}
|
||||
|
||||
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 == "" && s.keyName == "") {
|
||||
if !s.doCleanup {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ type StepKeyPair struct {
|
|||
PrivateKeyFile string
|
||||
|
||||
keyName string
|
||||
doCleanup bool
|
||||
}
|
||||
|
||||
func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -84,6 +85,7 @@ 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)
|
||||
|
||||
|
@ -167,13 +169,7 @@ func berToDer(ber string, ui packer.Ui) string {
|
|||
}
|
||||
|
||||
func (s *StepKeyPair) Cleanup(state multistep.StateBag) {
|
||||
// If we used an SSH private key file, do not go about deleting
|
||||
// keypairs
|
||||
if s.PrivateKeyFile != "" || (s.KeyPairName == "" && s.keyName == "") {
|
||||
return
|
||||
}
|
||||
// If no key name is set, then we never created it, so just return
|
||||
if s.TemporaryKeyPairName == "" {
|
||||
if !s.doCleanup {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue