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

View File

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