Merge pull request #3884 from rickard-von-essen/aws-ssh-ec2classic-fix

builder/amazon: guard aginst empty/nil PrivateIpAddress and updated tests.
This commit is contained in:
Rickard von Essen 2016-09-14 20:34:37 +02:00 committed by GitHub
commit 01ebb9c8f2
2 changed files with 3 additions and 3 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,11 +28,11 @@ 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, ""},