diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index 5e7d8872d..458a7226e 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -8,6 +8,7 @@ import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/communicator/ssh" "time" + "log" ) // SSHAddress returns a function that can be given to the SSH communicator @@ -20,7 +21,14 @@ func SSHAddress(e *ec2.EC2, port int) func(multistep.StateBag) (string, error) { if i.DNSName != "" { host = i.DNSName } else if i.VpcId != "" { - host = i.PrivateIpAddress + log.Printf("public ip from SSHAddress: %s", i.PublicIpAddress) + if i.PublicIpAddress != "" { + log.Printf("using public ip in SSHAddress") + host = i.PublicIpAddress + } else { + log.Printf("using private ip in SSHAddress") + host = i.PrivateIpAddress + } } if host != "" { diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index a122318c4..87110130b 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -110,6 +110,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi } s.instance = latestInstance.(*ec2.Instance) + log.Printf("Public IP: %s", s.instance.PublicIpAddress) if s.Debug { if s.instance.DNSName != "" {