From 110fd0e17fd2c72244aea499b47dac92a2b51055 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 21 Jul 2013 22:48:58 -0700 Subject: [PATCH] builder/amazon/common: SSH into private IP if in VPC --- builder/amazon/common/ssh.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index ea589189f..96e51cd20 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -11,8 +11,15 @@ import ( // for determining the SSH address based on the instance DNS name. 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) - return fmt.Sprintf("%s:%d", instance.DNSName, port), nil + if instance.VpcId != "" { + host = instance.PrivateIpAddress + } else { + host = instance.DNSName + } + + return fmt.Sprintf("%s:%d", host, port), nil } }