builder.gcp: use c.Comm for ssh
This commit is contained in:
parent
e0e6b0b8f7
commit
4982627dd2
|
@ -51,9 +51,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
steps := []multistep.Step{
|
steps := []multistep.Step{
|
||||||
new(StepCheckExistingImage),
|
new(StepCheckExistingImage),
|
||||||
&StepCreateSSHKey{
|
&StepCreateSSHKey{
|
||||||
Debug: b.config.PackerDebug,
|
Debug: b.config.PackerDebug,
|
||||||
DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName),
|
Comm: &b.config.Comm,
|
||||||
PrivateKeyFile: b.config.Comm.SSHPrivateKeyFile,
|
DebugKeyPath: fmt.Sprintf("gce_%s.pem", b.config.PackerBuildName),
|
||||||
},
|
},
|
||||||
&StepCreateInstance{
|
&StepCreateInstance{
|
||||||
Debug: b.config.PackerDebug,
|
Debug: b.config.PackerDebug,
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/helper/communicator"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
@ -17,9 +18,9 @@ import (
|
||||||
|
|
||||||
// StepCreateSSHKey represents a Packer build step that generates SSH key pairs.
|
// StepCreateSSHKey represents a Packer build step that generates SSH key pairs.
|
||||||
type StepCreateSSHKey struct {
|
type StepCreateSSHKey struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
DebugKeyPath string
|
Comm *communicator.Config
|
||||||
PrivateKeyFile string
|
DebugKeyPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run executes the Packer build step that generates SSH key pairs.
|
// Run executes the Packer build step that generates SSH key pairs.
|
||||||
|
@ -28,9 +29,9 @@ func (s *StepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
config := state.Get("config").(*Config)
|
config := state.Get("config").(*Config)
|
||||||
|
|
||||||
if s.PrivateKeyFile != "" {
|
if s.Comm.SSHPrivateKeyFile != "" {
|
||||||
ui.Say("Using existing SSH private key")
|
ui.Say("Using existing SSH private key")
|
||||||
privateKeyBytes, err := ioutil.ReadFile(s.PrivateKeyFile)
|
privateKeyBytes, err := ioutil.ReadFile(s.Comm.SSHPrivateKeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", fmt.Errorf(
|
state.Put("error", fmt.Errorf(
|
||||||
"Error loading configured private key file: %s", err))
|
"Error loading configured private key file: %s", err))
|
||||||
|
|
|
@ -3,6 +3,7 @@ package googlecompute
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/hashicorp/packer/helper/communicator"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -17,7 +18,8 @@ func TestStepCreateSSHKey_impl(t *testing.T) {
|
||||||
func TestStepCreateSSHKey_privateKey(t *testing.T) {
|
func TestStepCreateSSHKey_privateKey(t *testing.T) {
|
||||||
state := testState(t)
|
state := testState(t)
|
||||||
step := new(StepCreateSSHKey)
|
step := new(StepCreateSSHKey)
|
||||||
step.PrivateKeyFile = "test-fixtures/fake-key"
|
step.Comm = new(communicator.Config)
|
||||||
|
step.Comm.SSHPrivateKeyFile = "test-fixtures/fake-key"
|
||||||
defer step.Cleanup(state)
|
defer step.Cleanup(state)
|
||||||
|
|
||||||
// run the step
|
// run the step
|
||||||
|
@ -35,6 +37,7 @@ func TestStepCreateSSHKey_privateKey(t *testing.T) {
|
||||||
func TestStepCreateSSHKey(t *testing.T) {
|
func TestStepCreateSSHKey(t *testing.T) {
|
||||||
state := testState(t)
|
state := testState(t)
|
||||||
step := new(StepCreateSSHKey)
|
step := new(StepCreateSSHKey)
|
||||||
|
step.Comm = new(communicator.Config)
|
||||||
defer step.Cleanup(state)
|
defer step.Cleanup(state)
|
||||||
|
|
||||||
// run the step
|
// run the step
|
||||||
|
@ -62,6 +65,7 @@ func TestStepCreateSSHKey_debug(t *testing.T) {
|
||||||
|
|
||||||
state := testState(t)
|
state := testState(t)
|
||||||
step := new(StepCreateSSHKey)
|
step := new(StepCreateSSHKey)
|
||||||
|
step.Comm = new(communicator.Config)
|
||||||
step.Debug = true
|
step.Debug = true
|
||||||
step.DebugKeyPath = tf.Name()
|
step.DebugKeyPath = tf.Name()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue