From 51d2aac9f67c8c58fca25c91fff3f1d86f63c97c Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Thu, 23 Aug 2018 16:35:07 +0200 Subject: [PATCH] SSHPrivateKey => SSHPrivateKeyFile --- builder/alicloud/ecs/builder.go | 4 ++-- builder/alicloud/ecs/run_config.go | 2 +- builder/amazon/common/run_config.go | 6 +++--- builder/amazon/ebs/builder.go | 2 +- builder/amazon/ebssurrogate/builder.go | 2 +- builder/amazon/ebsvolume/builder.go | 2 +- builder/amazon/instance/builder.go | 2 +- builder/azure/arm/config.go | 4 ++-- builder/cloudstack/builder.go | 2 +- builder/cloudstack/config.go | 2 +- builder/googlecompute/builder.go | 2 +- builder/null/config.go | 6 +++--- builder/oneandone/step_create_sshkey.go | 4 ++-- builder/openstack/builder.go | 2 +- builder/openstack/run_config.go | 6 +++--- builder/oracle/classic/builder.go | 2 +- builder/oracle/oci/builder.go | 2 +- builder/parallels/common/ssh_config_test.go | 8 ++++---- builder/profitbricks/config.go | 2 +- builder/profitbricks/step_create_ssh_key.go | 4 ++-- builder/scaleway/builder.go | 2 +- builder/triton/builder.go | 2 +- builder/virtualbox/common/ssh_config_test.go | 8 ++++---- builder/vmware/common/ssh_config_test.go | 8 ++++---- helper/communicator/config.go | 16 ++++++++-------- 25 files changed, 51 insertions(+), 51 deletions(-) diff --git a/builder/alicloud/ecs/builder.go b/builder/alicloud/ecs/builder.go index 17037ca5e..bc9d9dcb6 100644 --- a/builder/alicloud/ecs/builder.go +++ b/builder/alicloud/ecs/builder.go @@ -98,7 +98,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &stepConfigAlicloudKeyPair{ Debug: b.config.PackerDebug, KeyPairName: b.config.SSHKeyPairName, - PrivateKeyFile: b.config.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, TemporaryKeyPairName: b.config.TemporaryKeyPairName, SSHAgentAuth: b.config.Comm.SSHAgentAuth, DebugKeyPath: fmt.Sprintf("ecs_%s.pem", b.config.PackerBuildName), @@ -230,7 +230,7 @@ func (b *Builder) isVpcSpecified() bool { func (b *Builder) isUserDataNeeded() bool { // Public key setup requires userdata - if b.config.RunConfig.Comm.SSHPrivateKey != "" { + if b.config.RunConfig.Comm.SSHPrivateKeyFile != "" { return true } diff --git a/builder/alicloud/ecs/run_config.go b/builder/alicloud/ecs/run_config.go index 2c52bb37b..c9b55fafd 100644 --- a/builder/alicloud/ecs/run_config.go +++ b/builder/alicloud/ecs/run_config.go @@ -41,7 +41,7 @@ type RunConfig struct { func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { if c.SSHKeyPairName == "" && c.TemporaryKeyPairName == "" && - c.Comm.SSHPrivateKey == "" && c.Comm.SSHPassword == "" && c.Comm.WinRMPassword == "" { + c.Comm.SSHPrivateKeyFile == "" && c.Comm.SSHPassword == "" && c.Comm.WinRMPassword == "" { c.TemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) } diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index dbafd0f38..578f6d0d3 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -68,7 +68,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { // temporary_key_pair_name has not been provided and we are not using // ssh_password. if c.SSHKeyPairName == "" && c.TemporaryKeyPairName == "" && - c.Comm.SSHPrivateKey == "" && c.Comm.SSHPassword == "" { + c.Comm.SSHPrivateKeyFile == "" && c.Comm.SSHPassword == "" { c.TemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) } @@ -94,9 +94,9 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { } if c.SSHKeyPairName != "" { - if c.Comm.Type == "winrm" && c.Comm.WinRMPassword == "" && c.Comm.SSHPrivateKey == "" { + if c.Comm.Type == "winrm" && c.Comm.WinRMPassword == "" && c.Comm.SSHPrivateKeyFile == "" { errs = append(errs, fmt.Errorf("ssh_private_key_file must be provided to retrieve the winrm password when using ssh_keypair_name.")) - } else if c.Comm.SSHPrivateKey == "" && !c.Comm.SSHAgentAuth { + } else if c.Comm.SSHPrivateKeyFile == "" && !c.Comm.SSHAgentAuth { errs = append(errs, fmt.Errorf("ssh_private_key_file must be provided or ssh_agent_auth enabled when ssh_keypair_name is specified.")) } } diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 1c698c353..5733038a2 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -184,7 +184,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName), KeyPairName: b.config.SSHKeyPairName, TemporaryKeyPairName: b.config.TemporaryKeyPairName, - PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKeyFile, }, &awscommon.StepSecurityGroup{ SecurityGroupIds: b.config.SecurityGroupIds, diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index e5b5c7ddc..657c49d5f 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -201,7 +201,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName), KeyPairName: b.config.SSHKeyPairName, TemporaryKeyPairName: b.config.TemporaryKeyPairName, - PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKeyFile, }, &awscommon.StepSecurityGroup{ SecurityGroupIds: b.config.SecurityGroupIds, diff --git a/builder/amazon/ebsvolume/builder.go b/builder/amazon/ebsvolume/builder.go index 7529896fd..b31ecd23b 100644 --- a/builder/amazon/ebsvolume/builder.go +++ b/builder/amazon/ebsvolume/builder.go @@ -176,7 +176,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName), KeyPairName: b.config.SSHKeyPairName, TemporaryKeyPairName: b.config.TemporaryKeyPairName, - PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKeyFile, }, &awscommon.StepSecurityGroup{ SecurityGroupIds: b.config.SecurityGroupIds, diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 8ad791b22..11c91edc1 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -261,7 +261,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe SSHAgentAuth: b.config.Comm.SSHAgentAuth, DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName), KeyPairName: b.config.SSHKeyPairName, - PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKeyFile, TemporaryKeyPairName: b.config.TemporaryKeyPairName, }, &awscommon.StepSecurityGroup{ diff --git a/builder/azure/arm/config.go b/builder/azure/arm/config.go index 5c81c5aa9..8e2f3c5a6 100644 --- a/builder/azure/arm/config.go +++ b/builder/azure/arm/config.go @@ -314,8 +314,8 @@ func setSshValues(c *Config) error { c.Comm.SSHTimeout = 20 * time.Minute } - if c.Comm.SSHPrivateKey != "" { - privateKeyBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKey) + if c.Comm.SSHPrivateKeyFile != "" { + privateKeyBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKeyFile) if err != nil { return err } diff --git a/builder/cloudstack/builder.go b/builder/cloudstack/builder.go index a655c810d..a16b20cfe 100644 --- a/builder/cloudstack/builder.go +++ b/builder/cloudstack/builder.go @@ -67,7 +67,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("cs_%s.pem", b.config.PackerBuildName), KeyPair: b.config.Keypair, - PrivateKeyFile: b.config.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, SSHAgentAuth: b.config.Comm.SSHAgentAuth, TemporaryKeyPairName: b.config.TemporaryKeypairName, }, diff --git a/builder/cloudstack/config.go b/builder/cloudstack/config.go index a01d66eb7..0c685771a 100644 --- a/builder/cloudstack/config.go +++ b/builder/cloudstack/config.go @@ -127,7 +127,7 @@ func NewConfig(raws ...interface{}) (*Config, error) { // then create a temporary one, but only if the temporary_keypair_name has not // been provided. if c.Keypair == "" && c.TemporaryKeypairName == "" && - c.Comm.SSHPrivateKey == "" && c.Comm.SSHPassword == "" { + c.Comm.SSHPrivateKeyFile == "" && c.Comm.SSHPassword == "" { c.TemporaryKeypairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) } diff --git a/builder/googlecompute/builder.go b/builder/googlecompute/builder.go index c532fee11..93dc59480 100644 --- a/builder/googlecompute/builder.go +++ b/builder/googlecompute/builder.go @@ -53,7 +53,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &StepCreateSSHKey{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, }, &StepCreateInstance{ Debug: b.config.PackerDebug, diff --git a/builder/null/config.go b/builder/null/config.go index 6556a5e4e..a9d54eeb0 100644 --- a/builder/null/config.go +++ b/builder/null/config.go @@ -43,14 +43,14 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { fmt.Errorf("a Username must be specified, please reference your communicator documentation")) } - if !c.CommConfig.SSHAgentAuth && c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKey == "" { + if !c.CommConfig.SSHAgentAuth && c.CommConfig.Password() == "" && c.CommConfig.SSHPrivateKeyFile == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("one authentication method must be specified, please reference your communicator documentation")) } if (c.CommConfig.SSHAgentAuth && - (c.CommConfig.SSHPassword != "" || c.CommConfig.SSHPrivateKey != "")) || - (c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKey != "") { + (c.CommConfig.SSHPassword != "" || c.CommConfig.SSHPrivateKeyFile != "")) || + (c.CommConfig.SSHPassword != "" && c.CommConfig.SSHPrivateKeyFile != "") { errs = packer.MultiErrorAppend(errs, fmt.Errorf("only one of ssh_agent_auth, ssh_password, and ssh_private_key_file must be specified")) diff --git a/builder/oneandone/step_create_sshkey.go b/builder/oneandone/step_create_sshkey.go index a27561c1f..f03ece03a 100644 --- a/builder/oneandone/step_create_sshkey.go +++ b/builder/oneandone/step_create_sshkey.go @@ -21,8 +21,8 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult ui := state.Get("ui").(packer.Ui) c := state.Get("config").(*Config) - if c.Comm.SSHPrivateKey != "" { - pemBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKey) + if c.Comm.SSHPrivateKeyFile != "" { + pemBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKeyFile) if err != nil { ui.Error(err.Error()) diff --git a/builder/openstack/builder.go b/builder/openstack/builder.go index 4d797309f..485580801 100644 --- a/builder/openstack/builder.go +++ b/builder/openstack/builder.go @@ -84,7 +84,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe DebugKeyPath: fmt.Sprintf("os_%s.pem", b.config.PackerBuildName), KeyPairName: b.config.SSHKeyPairName, TemporaryKeyPairName: b.config.TemporaryKeyPairName, - PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.RunConfig.Comm.SSHPrivateKeyFile, SSHAgentAuth: b.config.RunConfig.Comm.SSHAgentAuth, }, &StepSourceImageInfo{ diff --git a/builder/openstack/run_config.go b/builder/openstack/run_config.go index ccc87dffc..62f6d60b3 100644 --- a/builder/openstack/run_config.go +++ b/builder/openstack/run_config.go @@ -103,7 +103,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { // temporary_key_pair_name has not been provided and we are not using // ssh_password. if c.SSHKeyPairName == "" && c.TemporaryKeyPairName == "" && - c.Comm.SSHPrivateKey == "" && c.Comm.SSHPassword == "" { + c.Comm.SSHPrivateKeyFile == "" && c.Comm.SSHPassword == "" { c.TemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) } @@ -116,9 +116,9 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { errs := c.Comm.Prepare(ctx) if c.SSHKeyPairName != "" { - if c.Comm.Type == "winrm" && c.Comm.WinRMPassword == "" && c.Comm.SSHPrivateKey == "" { + if c.Comm.Type == "winrm" && c.Comm.WinRMPassword == "" && c.Comm.SSHPrivateKeyFile == "" { errs = append(errs, errors.New("A ssh_private_key_file must be provided to retrieve the winrm password when using ssh_keypair_name.")) - } else if c.Comm.SSHPrivateKey == "" && !c.Comm.SSHAgentAuth { + } else if c.Comm.SSHPrivateKeyFile == "" && !c.Comm.SSHAgentAuth { errs = append(errs, errors.New("A ssh_private_key_file must be provided or ssh_agent_auth enabled when ssh_keypair_name is specified.")) } } diff --git a/builder/oracle/classic/builder.go b/builder/oracle/classic/builder.go index d5c950d91..6f7615b8e 100644 --- a/builder/oracle/classic/builder.go +++ b/builder/oracle/classic/builder.go @@ -65,7 +65,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &ocommon.StepKeyPair{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("oci_classic_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, }, &stepCreateIPReservation{}, &stepAddKeysToAPI{}, diff --git a/builder/oracle/oci/builder.go b/builder/oracle/oci/builder.go index 672746829..2df6ef78e 100644 --- a/builder/oracle/oci/builder.go +++ b/builder/oracle/oci/builder.go @@ -54,7 +54,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &ocommon.StepKeyPair{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("oci_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, }, &stepCreateInstance{}, &stepInstanceInfo{}, diff --git a/builder/parallels/common/ssh_config_test.go b/builder/parallels/common/ssh_config_test.go index 43b83f3ad..7a96920bc 100644 --- a/builder/parallels/common/ssh_config_test.go +++ b/builder/parallels/common/ssh_config_test.go @@ -33,14 +33,14 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { var errs []error c = testSSHConfig() - c.Comm.SSHPrivateKey = "" + c.Comm.SSHPrivateKeyFile = "" errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %#v", errs) } c = testSSHConfig() - c.Comm.SSHPrivateKey = "/i/dont/exist" + c.Comm.SSHPrivateKeyFile = "/i/dont/exist" errs = c.Prepare(testConfigTemplate(t)) if len(errs) == 0 { t.Fatal("should have error") @@ -59,7 +59,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { } c = testSSHConfig() - c.Comm.SSHPrivateKey = tf.Name() + c.Comm.SSHPrivateKeyFile = tf.Name() errs = c.Prepare(testConfigTemplate(t)) if len(errs) == 0 { t.Fatal("should have error") @@ -70,7 +70,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { tf.Truncate(0) tf.Write([]byte(testPem)) c = testSSHConfig() - c.Comm.SSHPrivateKey = tf.Name() + c.Comm.SSHPrivateKeyFile = tf.Name() errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %#v", errs) diff --git a/builder/profitbricks/config.go b/builder/profitbricks/config.go index f969d87de..4c9260a18 100644 --- a/builder/profitbricks/config.go +++ b/builder/profitbricks/config.go @@ -53,7 +53,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { var errs *packer.MultiError - if c.Comm.SSHPassword == "" && c.Comm.SSHPrivateKey == "" { + if c.Comm.SSHPassword == "" && c.Comm.SSHPrivateKeyFile == "" { errs = packer.MultiErrorAppend( errs, errors.New("Either ssh private key path or ssh password must be set.")) } diff --git a/builder/profitbricks/step_create_ssh_key.go b/builder/profitbricks/step_create_ssh_key.go index be0b973a8..6e041a8e8 100644 --- a/builder/profitbricks/step_create_ssh_key.go +++ b/builder/profitbricks/step_create_ssh_key.go @@ -21,8 +21,8 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult ui := state.Get("ui").(packer.Ui) c := state.Get("config").(*Config) - if c.Comm.SSHPrivateKey != "" { - pemBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKey) + if c.Comm.SSHPrivateKeyFile != "" { + pemBytes, err := ioutil.ReadFile(c.Comm.SSHPrivateKeyFile) if err != nil { ui.Error(err.Error()) diff --git a/builder/scaleway/builder.go b/builder/scaleway/builder.go index f7a19927d..f0c5fc8ab 100644 --- a/builder/scaleway/builder.go +++ b/builder/scaleway/builder.go @@ -51,7 +51,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &stepCreateSSHKey{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("scw_%s.pem", b.config.PackerBuildName), - PrivateKeyFile: b.config.Comm.SSHPrivateKey, + PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile, }, new(stepCreateServer), new(stepServerInfo), diff --git a/builder/triton/builder.go b/builder/triton/builder.go index e260cd536..1d5c7f583 100644 --- a/builder/triton/builder.go +++ b/builder/triton/builder.go @@ -38,7 +38,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { // If we are using an SSH agent to sign requests, and no private key has been // specified for SSH, use the agent for connecting for provisioning. - if b.config.AccessConfig.KeyMaterial == "" && b.config.Comm.SSHPrivateKey == "" { + if b.config.AccessConfig.KeyMaterial == "" && b.config.Comm.SSHPrivateKeyFile == "" { b.config.Comm.SSHAgentAuth = true } diff --git a/builder/virtualbox/common/ssh_config_test.go b/builder/virtualbox/common/ssh_config_test.go index b7dc7f90e..1c89c8770 100644 --- a/builder/virtualbox/common/ssh_config_test.go +++ b/builder/virtualbox/common/ssh_config_test.go @@ -64,14 +64,14 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { var errs []error c = testSSHConfig() - c.Comm.SSHPrivateKey = "" + c.Comm.SSHPrivateKeyFile = "" errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %#v", errs) } c = testSSHConfig() - c.Comm.SSHPrivateKey = "/i/dont/exist" + c.Comm.SSHPrivateKeyFile = "/i/dont/exist" errs = c.Prepare(testConfigTemplate(t)) if len(errs) == 0 { t.Fatal("should have error") @@ -90,7 +90,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { } c = testSSHConfig() - c.Comm.SSHPrivateKey = tf.Name() + c.Comm.SSHPrivateKeyFile = tf.Name() errs = c.Prepare(testConfigTemplate(t)) if len(errs) == 0 { t.Fatal("should have error") @@ -101,7 +101,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { tf.Truncate(0) tf.Write([]byte(testPem)) c = testSSHConfig() - c.Comm.SSHPrivateKey = tf.Name() + c.Comm.SSHPrivateKeyFile = tf.Name() errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %#v", errs) diff --git a/builder/vmware/common/ssh_config_test.go b/builder/vmware/common/ssh_config_test.go index 43b83f3ad..7a96920bc 100644 --- a/builder/vmware/common/ssh_config_test.go +++ b/builder/vmware/common/ssh_config_test.go @@ -33,14 +33,14 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { var errs []error c = testSSHConfig() - c.Comm.SSHPrivateKey = "" + c.Comm.SSHPrivateKeyFile = "" errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %#v", errs) } c = testSSHConfig() - c.Comm.SSHPrivateKey = "/i/dont/exist" + c.Comm.SSHPrivateKeyFile = "/i/dont/exist" errs = c.Prepare(testConfigTemplate(t)) if len(errs) == 0 { t.Fatal("should have error") @@ -59,7 +59,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { } c = testSSHConfig() - c.Comm.SSHPrivateKey = tf.Name() + c.Comm.SSHPrivateKeyFile = tf.Name() errs = c.Prepare(testConfigTemplate(t)) if len(errs) == 0 { t.Fatal("should have error") @@ -70,7 +70,7 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) { tf.Truncate(0) tf.Write([]byte(testPem)) c = testSSHConfig() - c.Comm.SSHPrivateKey = tf.Name() + c.Comm.SSHPrivateKeyFile = tf.Name() errs = c.Prepare(testConfigTemplate(t)) if len(errs) > 0 { t.Fatalf("should not have error: %#v", errs) diff --git a/helper/communicator/config.go b/helper/communicator/config.go index 4a9b97f77..a0db7b6eb 100644 --- a/helper/communicator/config.go +++ b/helper/communicator/config.go @@ -26,7 +26,7 @@ type Config struct { SSHPort int `mapstructure:"ssh_port"` SSHUsername string `mapstructure:"ssh_username"` SSHPassword string `mapstructure:"ssh_password"` - SSHPrivateKey string `mapstructure:"ssh_private_key_file"` + SSHPrivateKeyFile string `mapstructure:"ssh_private_key_file"` SSHPty bool `mapstructure:"ssh_pty"` SSHTimeout time.Duration `mapstructure:"ssh_timeout"` SSHAgentAuth bool `mapstructure:"ssh_agent_auth"` @@ -83,9 +83,9 @@ func (c *Config) SSHConfigFunc() func(multistep.StateBag) (*ssh.ClientConfig, er } var privateKeys [][]byte - if c.SSHPrivateKey != "" { + if c.SSHPrivateKeyFile != "" { // key based auth - bytes, err := ioutil.ReadFile(c.SSHPrivateKey) + bytes, err := ioutil.ReadFile(c.SSHPrivateKeyFile) if err != nil { return nil, fmt.Errorf("Error setting up SSH config: %s", err) } @@ -219,8 +219,8 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error { c.SSHBastionPort = 22 } - if c.SSHBastionPrivateKey == "" && c.SSHPrivateKey != "" { - c.SSHBastionPrivateKey = c.SSHPrivateKey + if c.SSHBastionPrivateKey == "" && c.SSHPrivateKeyFile != "" { + c.SSHBastionPrivateKey = c.SSHPrivateKeyFile } } @@ -240,11 +240,11 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error { errs = append(errs, errors.New("An ssh_username must be specified\n Note: some builders used to default ssh_username to \"root\".")) } - if c.SSHPrivateKey != "" { - if _, err := os.Stat(c.SSHPrivateKey); err != nil { + if c.SSHPrivateKeyFile != "" { + if _, err := os.Stat(c.SSHPrivateKeyFile); err != nil { errs = append(errs, fmt.Errorf( "ssh_private_key_file is invalid: %s", err)) - } else if _, err := SSHFileSigner(c.SSHPrivateKey); err != nil { + } else if _, err := SSHFileSigner(c.SSHPrivateKeyFile); err != nil { errs = append(errs, fmt.Errorf( "ssh_private_key_file is invalid: %s", err)) }