github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/googlecompute/ssh.go (about)

     1  package googlecompute
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/packer/helper/multistep"
     7  	"golang.org/x/crypto/ssh"
     8  )
     9  
    10  func commHost(state multistep.StateBag) (string, error) {
    11  	ipAddress := state.Get("instance_ip").(string)
    12  	return ipAddress, nil
    13  }
    14  
    15  // sshConfig returns the ssh configuration.
    16  func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
    17  	config := state.Get("config").(*Config)
    18  	privateKey := state.Get("ssh_private_key").(string)
    19  
    20  	signer, err := ssh.ParsePrivateKey([]byte(privateKey))
    21  	if err != nil {
    22  		return nil, fmt.Errorf("Error setting up SSH config: %s", err)
    23  	}
    24  
    25  	return &ssh.ClientConfig{
    26  		User: config.Comm.SSHUsername,
    27  		Auth: []ssh.AuthMethod{
    28  			ssh.PublicKeys(signer),
    29  		},
    30  		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
    31  	}, nil
    32  }