From b3aae89a535565bb193150f6488d56b7ac838740 Mon Sep 17 00:00:00 2001 From: "bozhi.ch" Date: Sun, 16 Sep 2018 18:19:00 +0800 Subject: [PATCH] fix attaching keypair error due to missing keypair name --- builder/alicloud/ecs/builder.go | 4 +++- builder/alicloud/ecs/step_attach_keypair.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/builder/alicloud/ecs/builder.go b/builder/alicloud/ecs/builder.go index 3b2688b1f..cc9c438a1 100644 --- a/builder/alicloud/ecs/builder.go +++ b/builder/alicloud/ecs/builder.go @@ -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{ diff --git a/builder/alicloud/ecs/step_attach_keypair.go b/builder/alicloud/ecs/step_attach_keypair.go index 9f5b63676..88deabbb3 100644 --- a/builder/alicloud/ecs/step_attach_keypair.go +++ b/builder/alicloud/ecs/step_attach_keypair.go @@ -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 }