fix attaching keypair error due to missing keypair name

This commit is contained in:
bozhi.ch 2018-09-16 18:19:00 +08:00
parent 30754a1ed6
commit b3aae89a53
2 changed files with 6 additions and 2 deletions

View File

@ -146,7 +146,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
})
}
steps = append(steps,
&stepAttachKeyPair{},
&stepAttachKeyPair{
Comm: &b.config.Comm,
},
&stepRunAlicloudInstance{},
&stepMountAlicloudDisk{},
&communicator.StepConnect{

View File

@ -8,11 +8,13 @@ import (
"github.com/denverdino/aliyungo/common"
"github.com/denverdino/aliyungo/ecs"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
type stepAttachKeyPair struct {
Comm *communicator.Config
}
func (s *stepAttachKeyPair) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
@ -21,7 +23,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.SSHKeyPairName
keyPairName := s.Comm.SSHKeyPairName
if keyPairName == "" {
return multistep.ActionContinue
}