config.Comm.SSHKeyPair => SSHKeyPairName

This commit is contained in:
Adrien Delorme 2018-08-28 16:10:39 +02:00
parent 3a4bb26150
commit 9a9b82715b
7 changed files with 17 additions and 17 deletions

View File

@ -21,7 +21,7 @@ func (s *stepAttachKeyPair) Run(_ context.Context, state multistep.StateBag) mul
config := state.Get("config").(Config)
instance := state.Get("instance").(*ecs.InstanceAttributesType)
timeoutPoint := time.Now().Add(120 * time.Second)
keyPairName := config.Comm.SSHKeyPair
keyPairName := config.Comm.SSHKeyPairName
if keyPairName == "" {
return multistep.ActionContinue
}
@ -55,7 +55,7 @@ func (s *stepAttachKeyPair) Cleanup(state multistep.StateBag) {
config := state.Get("config").(Config)
ui := state.Get("ui").(packer.Ui)
instance := state.Get("instance").(*ecs.InstanceAttributesType)
keyPairName := config.Comm.SSHKeyPair
keyPairName := config.Comm.SSHKeyPairName
if keyPairName == "" {
return
}

View File

@ -38,7 +38,7 @@ func (s *stepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.State
return multistep.ActionHalt
}
config.Comm.SSHKeyPair = s.KeyPairName
config.Comm.SSHKeyPairName = s.KeyPairName
config.Comm.SSHPrivateKey = privateKeyBytes
return multistep.ActionContinue
@ -77,7 +77,7 @@ func (s *stepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.State
s.keyName = s.TemporaryKeyPairName
// Set some state data for use in future steps
config.Comm.SSHKeyPair = s.keyName
config.Comm.SSHKeyPairName = s.keyName
config.Comm.SSHPrivateKey = []byte(keyResp.PrivateKeyBody)
// If we're in debug mode, output the private key to the working

View File

@ -66,7 +66,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
// ssh_private_key_file, then create a temporary one, but only if the
// temporary_key_pair_name has not been provided and we are not using
// ssh_password.
if c.Comm.SSHKeyPair == "" && c.TemporaryKeyPairName == "" &&
if c.Comm.SSHKeyPairName == "" && c.TemporaryKeyPairName == "" &&
c.Comm.SSHPrivateKeyFile == "" && c.Comm.SSHPassword == "" {
c.TemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID())
@ -92,7 +92,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
errs = append(errs, fmt.Errorf("Unknown interface type: %s", c.SSHInterface))
}
if c.Comm.SSHKeyPair != "" {
if c.Comm.SSHKeyPairName != "" {
if c.Comm.Type == "winrm" && c.Comm.WinRMPassword == "" && c.Comm.SSHPrivateKeyFile == "" {
errs = append(errs, fmt.Errorf("ssh_private_key_file must be provided to retrieve the winrm password when using ssh_keypair_name."))
} else if c.Comm.SSHPrivateKeyFile == "" && !c.Comm.SSHAgentAuth {

View File

@ -39,14 +39,14 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
return multistep.ActionContinue
}
if s.Comm.SSHAgentAuth && s.Comm.SSHKeyPair == "" {
if s.Comm.SSHAgentAuth && s.Comm.SSHKeyPairName == "" {
ui.Say("Using SSH Agent with key pair in Source AMI")
return multistep.ActionContinue
}
if s.Comm.SSHAgentAuth && s.Comm.SSHKeyPair != "" {
ui.Say(fmt.Sprintf("Using SSH Agent for existing key pair %s", s.Comm.SSHKeyPair))
state.Put("keyPair", s.Comm.SSHKeyPair)
if s.Comm.SSHAgentAuth && s.Comm.SSHKeyPairName != "" {
ui.Say(fmt.Sprintf("Using SSH Agent for existing key pair %s", s.Comm.SSHKeyPairName))
state.Put("keyPair", s.Comm.SSHKeyPairName)
return multistep.ActionContinue
}
@ -69,7 +69,7 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
s.doCleanup = true
// Set some data for use in future steps
s.Comm.SSHKeyPair = s.TemporaryKeyPairName
s.Comm.SSHKeyPairName = s.TemporaryKeyPairName
s.Comm.SSHPrivateKey = []byte(*keyResp.KeyMaterial)
// If we're in debug mode, output the private key to the working

View File

@ -39,7 +39,7 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
}
config.Comm.SSHPrivateKey = privateKeyBytes
config.Comm.SSHKeyPair = s.KeyPairName
config.Comm.SSHKeyPairName = s.KeyPairName
return multistep.ActionContinue
}
@ -51,13 +51,13 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
if s.SSHAgentAuth && s.KeyPairName != "" {
ui.Say(fmt.Sprintf("Using SSH Agent for existing key pair %s", s.KeyPairName))
config.Comm.SSHKeyPair = ""
config.Comm.SSHKeyPairName = ""
return multistep.ActionContinue
}
if s.TemporaryKeyPairName == "" {
ui.Say("Not using temporary keypair")
config.Comm.SSHKeyPair = ""
config.Comm.SSHKeyPairName = ""
return multistep.ActionContinue
}
@ -117,7 +117,7 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
s.doCleanup = true
// Set some state data for use in future steps
config.Comm.SSHKeyPair = s.TemporaryKeyPairName
config.Comm.SSHKeyPairName = s.TemporaryKeyPairName
config.Comm.SSHPrivateKey = []byte(keypair.PrivateKey)
return multistep.ActionContinue

View File

@ -107,7 +107,7 @@ func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) m
}
// Add keypair to the server create options.
keyName := config.Comm.SSHKeyPair
keyName := config.Comm.SSHKeyPairName
if keyName != "" {
serverOptsExt = keypairs.CreateOptsExt{
CreateOptsBuilder: serverOptsExt,

View File

@ -29,7 +29,7 @@ type Config struct {
SSHPassword string `mapstructure:"ssh_password"`
SSHPublicKey []byte `mapstructure:"ssh_public_key"`
SSHPrivateKey []byte `mapstructure:"ssh_private_key"`
SSHKeyPair string `mapstructure:"ssh_keypair_name"`
SSHKeyPairName string `mapstructure:"ssh_keypair_name"`
SSHPrivateKeyFile string `mapstructure:"ssh_private_key_file"`
SSHPty bool `mapstructure:"ssh_pty"`
SSHTimeout time.Duration `mapstructure:"ssh_timeout"`