packer-cn/builder/googlecompute/ssh.go

33 lines
777 B
Go
Raw Normal View History

package googlecompute
import (
"fmt"
"github.com/hashicorp/packer/helper/multistep"
2015-06-09 00:34:20 -04:00
"golang.org/x/crypto/ssh"
)
func commHost(state multistep.StateBag) (string, error) {
ipAddress := state.Get("instance_ip").(string)
return ipAddress, nil
}
// sshConfig returns the ssh configuration.
func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
config := state.Get("config").(*Config)
privateKey := state.Get("ssh_private_key").(string)
signer, err := ssh.ParsePrivateKey([]byte(privateKey))
if err != nil {
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
}
2013-12-13 21:06:49 -05:00
return &ssh.ClientConfig{
2015-06-13 18:30:16 -04:00
User: config.Comm.SSHUsername,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil
}