helper/ssh: convert to InstanceState

This commit is contained in:
Mitchell Hashimoto 2014-09-16 16:55:02 -07:00
parent 0de633abeb
commit f117e33c9d
2 changed files with 22 additions and 18 deletions

View File

@ -43,8 +43,8 @@ type SSHConfig struct {
}
// VerifySSH is used to verify the ConnInfo is usable by remote-exec
func VerifySSH(s *terraform.ResourceState) error {
connType := s.ConnInfo["type"]
func VerifySSH(s *terraform.InstanceState) error {
connType := s.Ephemeral.ConnInfo["type"]
switch connType {
case "":
case "ssh":
@ -54,9 +54,9 @@ func VerifySSH(s *terraform.ResourceState) error {
return nil
}
// ParseSSHConfig is used to convert the ConnInfo of the ResourceState into
// ParseSSHConfig is used to convert the ConnInfo of the InstanceState into
// a SSHConfig struct
func ParseSSHConfig(s *terraform.ResourceState) (*SSHConfig, error) {
func ParseSSHConfig(s *terraform.InstanceState) (*SSHConfig, error) {
sshConf := &SSHConfig{}
decConf := &mapstructure.DecoderConfig{
WeaklyTypedInput: true,
@ -66,7 +66,7 @@ func ParseSSHConfig(s *terraform.ResourceState) (*SSHConfig, error) {
if err != nil {
return nil, err
}
if err := dec.Decode(s.ConnInfo); err != nil {
if err := dec.Decode(s.Ephemeral.ConnInfo); err != nil {
return nil, err
}
if sshConf.User == "" {

View File

@ -7,30 +7,34 @@ import (
)
func TestResourceProvider_verifySSH(t *testing.T) {
r := &terraform.ResourceState{
ConnInfo: map[string]string{
"type": "telnet",
r := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{
ConnInfo: map[string]string{
"type": "telnet",
},
},
}
if err := VerifySSH(r); err == nil {
t.Fatalf("expected error with telnet")
}
r.ConnInfo["type"] = "ssh"
r.Ephemeral.ConnInfo["type"] = "ssh"
if err := VerifySSH(r); err != nil {
t.Fatalf("err: %v", err)
}
}
func TestResourceProvider_sshConfig(t *testing.T) {
r := &terraform.ResourceState{
ConnInfo: map[string]string{
"type": "ssh",
"user": "root",
"password": "supersecret",
"key_file": "/my/key/file.pem",
"host": "127.0.0.1",
"port": "22",
"timeout": "30s",
r := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{
ConnInfo: map[string]string{
"type": "ssh",
"user": "root",
"password": "supersecret",
"key_file": "/my/key/file.pem",
"host": "127.0.0.1",
"port": "22",
"timeout": "30s",
},
},
}