ssh: return error if host is empty
This commit is contained in:
parent
851e6dcdbb
commit
c9ea93308a
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/hashicorp/terraform/communicator/shared"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/xanzy/ssh-agent"
|
||||
sshagent "github.com/xanzy/ssh-agent"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/agent"
|
||||
"golang.org/x/crypto/ssh/knownhosts"
|
||||
|
@ -93,6 +93,12 @@ func parseConnectionInfo(s *terraform.InstanceState) (*connectionInfo, error) {
|
|||
connInfo.User = DefaultUser
|
||||
}
|
||||
|
||||
// Check if host is empty.
|
||||
// Otherwise return error.
|
||||
if connInfo.Host == "" {
|
||||
return nil, fmt.Errorf("host for provisioner cannot be empty")
|
||||
}
|
||||
|
||||
// Format the host if needed.
|
||||
// Needed for IPv6 support.
|
||||
connInfo.Host = shared.IpFormat(connInfo.Host)
|
||||
|
|
|
@ -131,3 +131,24 @@ func TestProvisioner_connInfoHostname(t *testing.T) {
|
|||
t.Fatalf("bad %v", conf)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProvisioner_connInfoEmptyHostname(t *testing.T) {
|
||||
r := &terraform.InstanceState{
|
||||
Ephemeral: terraform.EphemeralState{
|
||||
ConnInfo: map[string]string{
|
||||
"type": "ssh",
|
||||
"user": "root",
|
||||
"password": "supersecret",
|
||||
"private_key": "someprivatekeycontents",
|
||||
"host": "",
|
||||
"port": "22",
|
||||
"timeout": "30s",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, err := parseConnectionInfo(r)
|
||||
if err == nil {
|
||||
t.Fatalf("bad: should not allow empty host")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue