diff --git a/builder/alicloud/ecs/step_config_key_pair.go b/builder/alicloud/ecs/step_config_key_pair.go index 9d502ea68..c4307378e 100644 --- a/builder/alicloud/ecs/step_config_key_pair.go +++ b/builder/alicloud/ecs/step_config_key_pair.go @@ -3,7 +3,6 @@ package ecs import ( "context" "fmt" - "io/ioutil" "os" "runtime" @@ -28,10 +27,9 @@ func (s *stepConfigAlicloudKeyPair) Run(_ context.Context, state multistep.State if s.Comm.SSHPrivateKeyFile != "" { ui.Say("Using existing SSH private key") - privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) + privateKeyBytes, err := s.Comm.ReadSSHPrivateKeyFile() if err != nil { - state.Put("error", fmt.Errorf( - "Error loading configured private key file: %s", err)) + state.Put("error", err) return multistep.ActionHalt } diff --git a/builder/amazon/common/step_key_pair.go b/builder/amazon/common/step_key_pair.go index 9b34b64af..ba72b5668 100644 --- a/builder/amazon/common/step_key_pair.go +++ b/builder/amazon/common/step_key_pair.go @@ -3,7 +3,6 @@ package common import ( "context" "fmt" - "io/ioutil" "os" "runtime" @@ -26,10 +25,9 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep if s.Comm.SSHPrivateKeyFile != "" { ui.Say("Using existing SSH private key") - privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) + privateKeyBytes, err := s.Comm.ReadSSHPrivateKeyFile() if err != nil { - state.Put("error", fmt.Errorf( - "Error loading configured private key file: %s", err)) + state.Put("error", err) return multistep.ActionHalt } diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index d72d28550..77daa67c0 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -326,7 +326,7 @@ func setSshValues(c *Config) error { } if c.Comm.SSHPrivateKeyFile != "" { - privateKeyBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKeyFile) + privateKeyBytes, err := c.Comm.ReadSSHPrivateKeyFile() if err != nil { return err } diff --git a/builder/cloudstack/step_keypair.go b/builder/cloudstack/step_keypair.go index f08bd706d..bb40534fe 100644 --- a/builder/cloudstack/step_keypair.go +++ b/builder/cloudstack/step_keypair.go @@ -3,7 +3,6 @@ package cloudstack import ( "context" "fmt" - "io/ioutil" "os" "runtime" @@ -23,10 +22,10 @@ func (s *stepKeypair) Run(_ context.Context, state multistep.StateBag) multistep ui := state.Get("ui").(packer.Ui) if s.Comm.SSHPrivateKeyFile != "" { - privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) + ui.Say("Using existing SSH private key") + privateKeyBytes, err := s.Comm.ReadSSHPrivateKeyFile() if err != nil { - state.Put("error", fmt.Errorf( - "Error loading configured private key file: %s", err)) + state.Put("error", err) return multistep.ActionHalt } diff --git a/builder/googlecompute/step_create_ssh_key.go b/builder/googlecompute/step_create_ssh_key.go index 889cf1b76..897e0a6a3 100644 --- a/builder/googlecompute/step_create_ssh_key.go +++ b/builder/googlecompute/step_create_ssh_key.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "os" "github.com/hashicorp/packer/helper/multistep" @@ -29,10 +28,9 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult if config.Comm.SSHPrivateKeyFile != "" { ui.Say("Using existing SSH private key") - privateKeyBytes, err := ioutil.ReadFile(config.Comm.SSHPrivateKeyFile) + privateKeyBytes, err := config.Comm.ReadSSHPrivateKeyFile() if err != nil { - state.Put("error", fmt.Errorf( - "Error loading configured private key file: %s", err)) + state.Put("error", err) return multistep.ActionHalt } diff --git a/builder/openstack/step_key_pair.go b/builder/openstack/step_key_pair.go index ccf1eaecf..a850b8056 100644 --- a/builder/openstack/step_key_pair.go +++ b/builder/openstack/step_key_pair.go @@ -28,10 +28,10 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep ui := state.Get("ui").(packer.Ui) if s.Comm.SSHPrivateKeyFile != "" { - privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) + ui.Say("Using existing SSH private key") + privateKeyBytes, err := s.Comm.ReadSSHPrivateKeyFile() if err != nil { - state.Put("error", fmt.Errorf( - "Error loading configured private key file: %s", err)) + state.Put("error", err) return multistep.ActionHalt } diff --git a/builder/oracle/common/step_ssh_key_pair.go b/builder/oracle/common/step_ssh_key_pair.go index 04e82b986..49a0fd01b 100644 --- a/builder/oracle/common/step_ssh_key_pair.go +++ b/builder/oracle/common/step_ssh_key_pair.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "os" "runtime" @@ -27,9 +26,9 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep ui := state.Get("ui").(packer.Ui) if s.Comm.SSHPrivateKeyFile != "" { - privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile) + ui.Say("Using existing SSH private key") + privateKeyBytes, err := s.Comm.ReadSSHPrivateKeyFile() if err != nil { - err = fmt.Errorf("Error loading configured private key file: %s", err) ui.Error(err.Error()) state.Put("error", err) return multistep.ActionHalt diff --git a/builder/profitbricks/step_create_ssh_key.go b/builder/profitbricks/step_create_ssh_key.go index f9678c751..68c34af33 100644 --- a/builder/profitbricks/step_create_ssh_key.go +++ b/builder/profitbricks/step_create_ssh_key.go @@ -5,7 +5,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" @@ -22,9 +21,9 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult c := state.Get("config").(*Config) if c.Comm.SSHPrivateKeyFile != "" { - pemBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKeyFile) - + pemBytes, err := c.Comm.ReadSSHPrivateKeyFile() if err != nil { + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } diff --git a/builder/scaleway/step_create_ssh_key.go b/builder/scaleway/step_create_ssh_key.go index c58875724..b2d211a9a 100644 --- a/builder/scaleway/step_create_ssh_key.go +++ b/builder/scaleway/step_create_ssh_key.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "encoding/pem" "fmt" - "io/ioutil" "log" "os" "runtime" @@ -28,10 +27,9 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult if config.Comm.SSHPrivateKeyFile != "" { ui.Say("Using existing SSH private key") - privateKeyBytes, err := ioutil.ReadFile(config.Comm.SSHPrivateKeyFile) + privateKeyBytes, err := config.Comm.ReadSSHPrivateKeyFile() if err != nil { - state.Put("error", fmt.Errorf( - "Error loading configured private key file: %s", err)) + state.Put("error", err) return multistep.ActionHalt }