builder/amazon: set flag to delete temporary keypair
This commit is contained in:
parent
1ec9525204
commit
602fd64c5d
|
@ -19,7 +19,8 @@ type StepKeyPair struct {
|
||||||
KeyPairName string
|
KeyPairName string
|
||||||
PrivateKeyFile string
|
PrivateKeyFile string
|
||||||
|
|
||||||
keyName string
|
keyName string
|
||||||
|
doCleanup bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
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
|
// Set the keyname so we know to delete it later
|
||||||
s.keyName = s.TemporaryKeyPairName
|
s.keyName = s.TemporaryKeyPairName
|
||||||
|
s.doCleanup = true
|
||||||
|
|
||||||
// Set some state data for use in future steps
|
// Set some state data for use in future steps
|
||||||
state.Put("keyPair", s.keyName)
|
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) {
|
func (s *StepKeyPair) Cleanup(state multistep.StateBag) {
|
||||||
// If no key name is set, then we never created it, so just return
|
if !s.doCleanup {
|
||||||
// If we used an SSH private key file, do not go about deleting
|
|
||||||
// keypairs
|
|
||||||
if s.PrivateKeyFile != "" || (s.KeyPairName == "" && s.keyName == "") {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,8 @@ type StepKeyPair struct {
|
||||||
KeyPairName string
|
KeyPairName string
|
||||||
PrivateKeyFile string
|
PrivateKeyFile string
|
||||||
|
|
||||||
keyName string
|
keyName string
|
||||||
|
doCleanup bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepKeyPair) Run(state multistep.StateBag) multistep.StepAction {
|
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))
|
ui.Say(fmt.Sprintf("Created temporary keypair: %s", s.TemporaryKeyPairName))
|
||||||
|
s.doCleanup = true
|
||||||
|
|
||||||
keypair.PrivateKey = berToDer(keypair.PrivateKey, ui)
|
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) {
|
func (s *StepKeyPair) Cleanup(state multistep.StateBag) {
|
||||||
// If we used an SSH private key file, do not go about deleting
|
if !s.doCleanup {
|
||||||
// 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 == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue