From 4982627dd26dcdded3b0c44cdd0e179c2c9d174e Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 28 Aug 2018 17:47:38 +0200 Subject: [PATCH] builder.gcp: use c.Comm for ssh --- builder/googlecompute/builder.go | 6 +++--- builder/googlecompute/step_create_ssh_key.go | 11 ++++++----- builder/googlecompute/step_create_ssh_key_test.go | 6 +++++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index 93dc59480..1c0909989 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -51,9 +51,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe steps := []multistep.Step{ new(StepCheckExistingImage), &StepCreateSSHKey{ - Debug: b.config.PackerDebug, - DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, + Debug: b.config.PackerDebug, + Comm: &b.config.Comm, + DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName), }, &StepCreateInstance{ Debug: b.config.PackerDebug, diff --git a/builder/googlecompute/step_create_ssh_key.go b/builder/googlecompute/step_create_ssh_key.go index 476ea454c..69742c5ea 100644 --- a/builder/googlecompute/step_create_ssh_key.go +++ b/builder/googlecompute/step_create_ssh_key.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "os" + "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" "golang.org/x/crypto/ssh" @@ -17,9 +18,9 @@ import ( // StepCreateSSHKey represents a Packer build step that generates SSH key pairs. type StepCreateSSHKey struct { - Debug bool - DebugKeyPath string - PrivateKeyFile string + Debug bool + Comm *communicator.Config + DebugKeyPath string } // Run executes the Packer build step that generates SSH key pairs. @@ -28,9 +29,9 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult ui := state.Get("ui").(packer.Ui) config := state.Get("config").(*Config) - if s.PrivateKeyFile != "" { + if s.Comm.SSHPrivateKeyFile != "" { ui.Say("Using existing SSH private key") - privateKeyBytes, err := ioutil.ReadFile(s.PrivateKeyFile) + privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) if err != nil { state.Put("error", fmt.Errorf( "Error loading configured private key file: %s", err)) diff --git a/builder/googlecompute/step_create_ssh_key_test.go b/builder/googlecompute/step_create_ssh_key_test.go index fbd8ae240..18da2e4a7 100644 --- a/builder/googlecompute/step_create_ssh_key_test.go +++ b/builder/googlecompute/step_create_ssh_key_test.go @@ -3,6 +3,7 @@ package googlecompute import ( "context" + "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "io/ioutil" @@ -17,7 +18,8 @@ func TestStepCreateSSHKey_impl(t *testing.T) { func TestStepCreateSSHKey_privateKey(t *testing.T) { state := testState(t) step := new(StepCreateSSHKey) - step.PrivateKeyFile = "test-fixtures/fake-key" + step.Comm = new(communicator.Config) + step.Comm.SSHPrivateKeyFile = "test-fixtures/fake-key" defer step.Cleanup(state) // run the step @@ -35,6 +37,7 @@ func TestStepCreateSSHKey_privateKey(t *testing.T) { func TestStepCreateSSHKey(t *testing.T) { state := testState(t) step := new(StepCreateSSHKey) + step.Comm = new(communicator.Config) defer step.Cleanup(state) // run the step @@ -62,6 +65,7 @@ func TestStepCreateSSHKey_debug(t *testing.T) { state := testState(t) step := new(StepCreateSSHKey) + step.Comm = new(communicator.Config) step.Debug = true step.DebugKeyPath = tf.Name()