diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 41c36d517..dde30fb59 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -287,8 +287,8 @@ type Config struct { VaultGCPOauthEngine string `mapstructure:"vault_gcp_oauth_engine"` // The time to wait between the creation of the instance used to create the image, // and the addition of SSH configuration, including SSH keys, to that instance. - // The delay is intended to protect packer from anything in the instance boot - // sequence that has potential to disrupt the creation of SSH configuration + // The delay is intended to protect packer from anything in the instance boot + // sequence that has potential to disrupt the creation of SSH configuration // (e.g. SSH user creation, SSH key creation) on the instance. // Note: All other instance metadata, including startup scripts, are still added to the instance // during it's creation. diff --git a/builder/googlecompute/driver_gce.go b/builder/googlecompute/driver_gce.go index 8678fd7eb..4766c6260 100644 --- a/builder/googlecompute/driver_gce.go +++ b/builder/googlecompute/driver_gce.go @@ -764,6 +764,6 @@ func (d *driverGCE) AddToInstanceMetadata(zone string, name string, metadata map case <-time.After(time.Second * 30): err = errors.New("time out while waiting for SSH keys to be added to instance") } - + return newErrCh, err -} \ No newline at end of file +} diff --git a/builder/googlecompute/driver_mock.go b/builder/googlecompute/driver_mock.go index bd455841b..38179d53f 100644 --- a/builder/googlecompute/driver_mock.go +++ b/builder/googlecompute/driver_mock.go @@ -93,7 +93,7 @@ type DriverMock struct { AddToInstanceMetadataName string AddToInstanceMetadataKVPairs map[string]string AddToInstanceMetadataErrCh <-chan error - AddToInstanceMetadataErr error + AddToInstanceMetadataErr error } func (d *DriverMock) CreateImage(name, description, family, zone, disk string, image_labels map[string]string, image_licenses []string, image_encryption_key *compute.CustomerEncryptionKey, imageStorageLocations []string) (<-chan *Image, <-chan error) { @@ -296,8 +296,8 @@ func (d *DriverMock) DeleteOSLoginSSHKey(user, fingerprint string) error { } func (d *DriverMock) AddToInstanceMetadata(zone string, name string, metadata map[string]string) (<-chan error, error) { - d.AddToInstanceMetadataZone = zone - d.AddToInstanceMetadataName = name + d.AddToInstanceMetadataZone = zone + d.AddToInstanceMetadataName = name d.AddToInstanceMetadataKVPairs = metadata resultCh := d.AddToInstanceMetadataErrCh @@ -308,4 +308,4 @@ func (d *DriverMock) AddToInstanceMetadata(zone string, name string, metadata ma } return resultCh, d.AddToInstanceMetadataErr -} \ No newline at end of file +} diff --git a/builder/googlecompute/startup.go b/builder/googlecompute/startup.go index bdb147479..743778a2c 100644 --- a/builder/googlecompute/startup.go +++ b/builder/googlecompute/startup.go @@ -1,7 +1,7 @@ package googlecompute import ( - "fmt" + "fmt" ) const StartupScriptKey string = "startup-script" @@ -57,4 +57,4 @@ SetMetadata %s %s exit $RETVAL `, StartupWrappedScriptKey, StartupScriptStatusKey, StartupScriptStatusDone) -var StartupScriptWindows string = "" \ No newline at end of file +var StartupScriptWindows string = "" diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index fa52ae8b6..f895a1058 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -5,9 +5,9 @@ import ( "errors" "fmt" "io/ioutil" + "log" "strings" "time" - "log" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer-plugin-sdk/multistep" @@ -142,7 +142,7 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) var errCh <-chan error metadataNoSSHKeys := make(map[string]string) - metadataSSHKeys := make(map[string]string) + metadataSSHKeys := make(map[string]string) metadataForInstance := make(map[string]string) metadataNoSSHKeys, metadataSSHKeys, errs := c.createInstanceMetadata(sourceImage, string(c.Comm.SSHPublicKey)) @@ -160,7 +160,7 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) // Union of both non-SSH key meta data and SSH key meta data addmap(metadataForInstance, metadataSSHKeys) - addmap(metadataForInstance, metadataNoSSHKeys) + addmap(metadataForInstance, metadataNoSSHKeys) } errCh, err = d.RunInstance(&InstanceConfig{ @@ -230,9 +230,9 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) if cancelled { return multistep.ActionHalt } - + log.Printf("[DEBUG] %s wait is over. Adding SSH keys to existing instance...", - c.WaitToAddSSHKeys.String()) + c.WaitToAddSSHKeys.String()) errCh, err = d.AddToInstanceMetadata(c.Zone, name, metadataSSHKeys) if err != nil { @@ -241,7 +241,7 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) return multistep.ActionHalt } } - + return multistep.ActionContinue } @@ -252,7 +252,7 @@ func (s *StepCreateInstance) waitForBoot(ctx context.Context, waitLen time.Durat return true case <-time.After(waitLen): } - + return false } @@ -316,7 +316,7 @@ func (s *StepCreateInstance) Cleanup(state multistep.StateBag) { } func addmap(a map[string]string, b map[string]string) { - for k,v := range b { + for k, v := range b { a[k] = v } -} \ No newline at end of file +} diff --git a/builder/googlecompute/step_create_instance_test.go b/builder/googlecompute/step_create_instance_test.go index 86870d86f..9db780d02 100644 --- a/builder/googlecompute/step_create_instance_test.go +++ b/builder/googlecompute/step_create_instance_test.go @@ -337,7 +337,7 @@ func TestCreateInstanceMetadata_metadataFile(t *testing.T) { c.MetadataFiles["user-data"] = fileName // create our metadata - metadataNoSSHKeys, _,err := c.createInstanceMetadata(image, "") + metadataNoSSHKeys, _, err := c.createInstanceMetadata(image, "") assert.True(t, err == nil, "Metadata creation should have succeeded.") @@ -391,14 +391,14 @@ func TestCreateInstanceMetadataWaitToAddSSHKeys(t *testing.T) { c := state.Get("config").(*Config) image := StubImage("test-image", "test-project", []string{}, 100) key := "abcdefgh12345678" - + var waitTime int = 4 c.WaitToAddSSHKeys = time.Duration(waitTime) * time.Second c.Metadata = map[string]string{ "metadatakey1": "xyz", "metadatakey2": "123", } - + // create our metadata metadataNoSSHKeys, metadataSSHKeys, err := c.createInstanceMetadata(image, key) @@ -406,8 +406,8 @@ func TestCreateInstanceMetadataWaitToAddSSHKeys(t *testing.T) { // ensure our metadata is listed assert.True(t, strings.Contains(metadataSSHKeys["ssh-keys"], key), "Instance metadata should contain provided SSH key") - assert.True(t, strings.Contains(metadataNoSSHKeys["metadatakey1"], "xyz"), "Instance metadata should contain provided key: metadatakey1") - assert.True(t, strings.Contains(metadataNoSSHKeys["metadatakey2"], "123"), "Instance metadata should contain provided key: metadatakey2") + assert.True(t, strings.Contains(metadataNoSSHKeys["metadatakey1"], "xyz"), "Instance metadata should contain provided key: metadatakey1") + assert.True(t, strings.Contains(metadataNoSSHKeys["metadatakey2"], "123"), "Instance metadata should contain provided key: metadatakey2") } func TestStepCreateInstanceWaitToAddSSHKeys(t *testing.T) { @@ -422,7 +422,7 @@ func TestStepCreateInstanceWaitToAddSSHKeys(t *testing.T) { d.GetImageResult = StubImage("test-image", "test-project", []string{}, 100) key := "abcdefgh12345678" - + var waitTime int = 5 c.WaitToAddSSHKeys = time.Duration(waitTime) * time.Second c.Comm.SSHPublicKey = []byte(key) @@ -455,14 +455,14 @@ func TestStepCreateInstanceNoWaitToAddSSHKeys(t *testing.T) { d.GetImageResult = StubImage("test-image", "test-project", []string{}, 100) key := "abcdefgh12345678" - + c.Comm.SSHPublicKey = []byte(key) c.Metadata = map[string]string{ "metadatakey1": "xyz", "metadatakey2": "123", } - + // run the step assert.Equal(t, step.Run(context.Background(), state), multistep.ActionContinue, "Step should have passed and continued.") @@ -472,4 +472,4 @@ func TestStepCreateInstanceNoWaitToAddSSHKeys(t *testing.T) { // cleanup step.Cleanup(state) -} \ No newline at end of file +}