builder/amazon/common: prefer public DNS if possible for SSH

This commit is contained in:
Mitchell Hashimoto 2013-07-31 09:30:52 -07:00
parent 19b6841e64
commit a2481f2300
1 changed files with 5 additions and 2 deletions

View File

@ -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