builder/amazon/common: prefer public DNS if possible for SSH
This commit is contained in:
parent
19b6841e64
commit
a2481f2300
|
@ -2,6 +2,7 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gossh "code.google.com/p/go.crypto/ssh"
|
gossh "code.google.com/p/go.crypto/ssh"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/goamz/ec2"
|
"github.com/mitchellh/goamz/ec2"
|
||||||
"github.com/mitchellh/packer/communicator/ssh"
|
"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) {
|
return func(state map[string]interface{}) (string, error) {
|
||||||
var host string
|
var host string
|
||||||
instance := state["instance"].(*ec2.Instance)
|
instance := state["instance"].(*ec2.Instance)
|
||||||
if instance.VpcId != "" {
|
if instance.DNSName != "" {
|
||||||
|
host = instance.DNSName
|
||||||
|
} else if instance.VpcId == "" {
|
||||||
host = instance.PrivateIpAddress
|
host = instance.PrivateIpAddress
|
||||||
} else {
|
} else {
|
||||||
host = instance.DNSName
|
return "", errors.New("couldn't determine IP address for instance")
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s:%d", host, port), nil
|
return fmt.Sprintf("%s:%d", host, port), nil
|
||||||
|
|
Loading…
Reference in New Issue