Properly set SSH key pair name.

This commit is contained in:
Stephen Fox 2019-02-04 12:12:18 -05:00
parent 4c2851013e
commit 25775886a8
1 changed files with 6 additions and 5 deletions

View File

@ -47,19 +47,20 @@ func (s *StepSshKeyPair) Run(_ context.Context, state multistep.StateBag) multis
ui.Say("Creating ephemeral key pair for SSH communicator...") ui.Say("Creating ephemeral key pair for SSH communicator...")
// TODO: Should we respect 's.Comm.SSHTemporaryKeyPairName'?
// It appears to be specific to certain other builders, but it is not
// mentioned in the virtualbox builders' documentation.
s.Comm.SSHKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID())
kp, err := newSshKeyPairBuilder().Build() kp, err := newSshKeyPairBuilder().
SetName(fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID())).
Build()
if err != nil { if err != nil {
state.Put("error", fmt.Errorf("Error creating temporary keypair: %s", err)) state.Put("error", fmt.Errorf("Error creating temporary keypair: %s", err))
return multistep.ActionHalt return multistep.ActionHalt
} }
s.Comm.SSHKeyPairName = kp.Name()
s.Comm.SSHTemporaryKeyPairName = kp.Name()
s.Comm.SSHPrivateKey = kp.PrivateKeyPemBlock() s.Comm.SSHPrivateKey = kp.PrivateKeyPemBlock()
s.Comm.SSHPublicKey = kp.PublicKeyAuthorizedKeysFormat(unixNewLine) s.Comm.SSHPublicKey = kp.PublicKeyAuthorizedKeysFormat(unixNewLine)
s.Comm.SSHClearAuthorizedKeys = true
ui.Say(fmt.Sprintf("Created ephemeral SSH key pair of type %s", kp.Description())) ui.Say(fmt.Sprintf("Created ephemeral SSH key pair of type %s", kp.Description()))