github.com/sneal/packer@v0.5.2/builder/googlecompute/ssh.go (about) 1 package googlecompute 2 3 import ( 4 "fmt" 5 6 gossh "code.google.com/p/go.crypto/ssh" 7 "github.com/mitchellh/multistep" 8 "github.com/mitchellh/packer/communicator/ssh" 9 ) 10 11 // sshAddress returns the ssh address. 12 func sshAddress(state multistep.StateBag) (string, error) { 13 config := state.Get("config").(*Config) 14 ipAddress := state.Get("instance_ip").(string) 15 return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil 16 } 17 18 // sshConfig returns the ssh configuration. 19 func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { 20 config := state.Get("config").(*Config) 21 privateKey := state.Get("ssh_private_key").(string) 22 23 keyring := new(ssh.SimpleKeychain) 24 if err := keyring.AddPEMKey(privateKey); err != nil { 25 return nil, fmt.Errorf("Error setting up SSH config: %s", err) 26 } 27 28 sshConfig := &gossh.ClientConfig{ 29 User: config.SSHUsername, 30 Auth: []gossh.ClientAuth{gossh.ClientAuthKeyring(keyring)}, 31 } 32 33 return sshConfig, nil 34 }