From 067155c344ffdbd233e8ea32c6db2bcd6753eb31 Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Wed, 14 Sep 2016 00:16:09 +0200 Subject: [PATCH 1/2] builder/amazon: guard aginst empty/nil PrivateIpAddress and updated tests. --- builder/amazon/common/ssh.go | 2 +- builder/amazon/common/ssh_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builder/amazon/common/ssh.go b/builder/amazon/common/ssh.go index da7f74ffb..6c38ad97c 100644 --- a/builder/amazon/common/ssh.go +++ b/builder/amazon/common/ssh.go @@ -34,7 +34,7 @@ func SSHHost(e ec2Describer, private bool) func(multistep.StateBag) (string, err } else if i.PrivateIpAddress != nil && *i.PrivateIpAddress != "" { host = *i.PrivateIpAddress } - } else if private { + } else if private && i.PrivateIpAddress != nil && *i.PrivateIpAddress != "" { host = *i.PrivateIpAddress } else if i.PublicDnsName != nil && *i.PublicDnsName != "" { host = *i.PublicDnsName diff --git a/builder/amazon/common/ssh_test.go b/builder/amazon/common/ssh_test.go index 4d2583e6f..ed9c0ae08 100644 --- a/builder/amazon/common/ssh_test.go +++ b/builder/amazon/common/ssh_test.go @@ -28,15 +28,15 @@ func TestSSHHost(t *testing.T) { wantHost string }{ {1, "", false, true, publicDNS}, - {1, "", true, true, publicDNS}, + {1, "", true, true, privateIP}, {1, "vpc-id", false, true, publicIP}, {1, "vpc-id", true, true, privateIP}, {2, "", false, true, publicDNS}, - {2, "", true, true, publicDNS}, + {2, "", true, true, privateIP}, {2, "vpc-id", false, true, publicIP}, {2, "vpc-id", true, true, privateIP}, - {3, "", false, false, ""}, - {3, "", true, false, ""}, + {2, "", false, true, publicDNS}, + {2, "", true, true, privateIP}, {3, "vpc-id", false, false, ""}, {3, "vpc-id", true, false, ""}, } From 3b47893eb85bc235510fe9edc5107fd83cef2d01 Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Wed, 14 Sep 2016 20:26:09 +0200 Subject: [PATCH 2/2] builder/amazon: reverted wrongly modified ssh_test's. --- builder/amazon/common/ssh_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/ssh_test.go b/builder/amazon/common/ssh_test.go index ed9c0ae08..9f1d4a53e 100644 --- a/builder/amazon/common/ssh_test.go +++ b/builder/amazon/common/ssh_test.go @@ -35,8 +35,8 @@ func TestSSHHost(t *testing.T) { {2, "", true, true, privateIP}, {2, "vpc-id", false, true, publicIP}, {2, "vpc-id", true, true, privateIP}, - {2, "", false, true, publicDNS}, - {2, "", true, true, privateIP}, + {3, "", false, false, ""}, + {3, "", true, false, ""}, {3, "vpc-id", false, false, ""}, {3, "vpc-id", true, false, ""}, }