From d1e0214bec701ff9cd6356a5d3f19e1e75c7cac1 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 20 Oct 2020 16:59:46 +0200 Subject: [PATCH] avoid panic debugging ssh key --- builder/googlecompute/builder.go | 1 + helper/communicator/step_debug_ssh_keys.go | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index a1295e71b..74df7f53d 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -66,6 +66,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack multistep.If(b.config.PackerDebug && b.config.Comm.SSHPrivateKeyFile == "", &communicator.StepDumpSSHKey{ Path: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName), + SSH: &b.config.Comm.SSH, }, ), &StepImportOSLoginSSHKey{ diff --git a/helper/communicator/step_debug_ssh_keys.go b/helper/communicator/step_debug_ssh_keys.go index ae662bacc..e6623fdf1 100644 --- a/helper/communicator/step_debug_ssh_keys.go +++ b/helper/communicator/step_debug_ssh_keys.go @@ -13,18 +13,15 @@ import ( // keypair somewhere. type StepDumpSSHKey struct { Path string + SSH *SSH } func (s *StepDumpSSHKey) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) - // Put communicator config into state so we can pass it to provisioners - // for specialized interpolation later - comm := state.Get("communicator_config").(Config) - ui.Message(fmt.Sprintf("Saving key for debug purposes: %s", s.Path)) - err := ioutil.WriteFile(s.Path, comm.SSHPrivateKey, 0700) + err := ioutil.WriteFile(s.Path, s.SSH.SSHPrivateKey, 0700) if err != nil { state.Put("error", fmt.Errorf("Error saving debug key: %s", err)) return multistep.ActionHalt