builder/amazon: guard aginst empty/nil PrivateIpAddress and updated tests.

This commit is contained in:
Rickard von Essen 2016-09-14 00:16:09 +02:00
parent f6f50cd1df
commit 067155c344
No known key found for this signature in database
GPG Key ID: E0C0327388876CBA
2 changed files with 5 additions and 5 deletions

View File

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

View File

@ -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, ""},
}