From dfc332f98c30a4dc0b868a48329f6a62aea7d65e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 May 2013 11:36:26 -0700 Subject: [PATCH] builder/amazonebs: Add ssh_* settings --- builder/amazonebs/builder.go | 2 ++ builder/amazonebs/step_connect_ssh.go | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/builder/amazonebs/builder.go b/builder/amazonebs/builder.go index baed224b9..95bbca767 100644 --- a/builder/amazonebs/builder.go +++ b/builder/amazonebs/builder.go @@ -22,6 +22,8 @@ type config struct { Region string SourceAmi string `mapstructure:"source_ami"` InstanceType string `mapstructure:"instance_type"` + SSHUsername string `mapstructure:"ssh_username"` + SSHPort int `mapstructure:"ssh_port"` // Configuration of the resulting AMI AMIName string `mapstructure:"ami_name"` diff --git a/builder/amazonebs/step_connect_ssh.go b/builder/amazonebs/step_connect_ssh.go index 349d86987..f3a9544d2 100644 --- a/builder/amazonebs/step_connect_ssh.go +++ b/builder/amazonebs/step_connect_ssh.go @@ -16,6 +16,7 @@ type stepConnectSSH struct { } func (s *stepConnectSSH) Run(state map[string]interface{}) StepAction { + config := state["config"].(config) instance := state["instance"].(*ec2.Instance) privateKey := state["privateKey"].(string) ui := state["ui"].(packer.Ui) @@ -31,7 +32,7 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) StepAction { // Build the actual SSH client configuration sshConfig := &gossh.ClientConfig{ - User: "ubuntu", + User: config.SSHUsername, Auth: []gossh.ClientAuth{ gossh.ClientAuthKeyring(keyring), }, @@ -43,9 +44,9 @@ func (s *stepConnectSSH) Run(state map[string]interface{}) StepAction { time.Sleep(time.Duration(i) * time.Second) log.Printf( - "Opening TCP conn for SSH to %s:22 (attempt %d)", - instance.DNSName, i+1) - s.conn, err = net.Dial("tcp", fmt.Sprintf("%s:22", instance.DNSName)) + "Opening TCP conn for SSH to %s:%d (attempt %d)", + instance.DNSName, config.SSHPort, i+1) + s.conn, err = net.Dial("tcp", fmt.Sprintf("%s:%d", instance.DNSName, config.SSHPort)) if err != nil { continue }