From a2481f23003d1069d7dd95ebd0066950a95ffd1f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 Jul 2013 09:30:52 -0700 Subject: [PATCH] builder/amazon/common: prefer public DNS if possible for SSH --- builder/amazon/common/ssh.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index 96e51cd20..adcbb5391 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -2,6 +2,7 @@ package common import ( gossh "code.google.com/p/go.crypto/ssh" + "errors" "fmt" "github.com/mitchellh/goamz/ec2" "github.com/mitchellh/packer/communicator/ssh" @@ -13,10 +14,12 @@ func SSHAddress(port int) func(map[string]interface{}) (string, error) { return func(state map[string]interface{}) (string, error) { var host string instance := state["instance"].(*ec2.Instance) - if instance.VpcId != "" { + if instance.DNSName != "" { + host = instance.DNSName + } else if instance.VpcId == "" { host = instance.PrivateIpAddress } else { - host = instance.DNSName + return "", errors.New("couldn't determine IP address for instance") } return fmt.Sprintf("%s:%d", host, port), nil