diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index ce31e0d1d..3e65bd6c4 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -8,9 +8,9 @@ import ( "context" "errors" "fmt" - "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go/service/iam" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/communicator" diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index ac3296196..78ccbdd1a 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -8,11 +8,11 @@ import ( "context" "errors" "fmt" - "github.com/aws/aws-sdk-go/service/iam" "os" "strings" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go/service/iam" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/communicator" diff --git a/builder/digitalocean/config.go b/builder/digitalocean/config.go index eef4e5e13..b087cdb9e 100644 --- a/builder/digitalocean/config.go +++ b/builder/digitalocean/config.go @@ -142,6 +142,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } var errs *packer.MultiError + if es := c.Comm.Prepare(&c.ctx); len(es) > 0 { errs = packer.MultiErrorAppend(errs, es...) } diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index bb7cd21b1..7aeeb4cb5 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -121,7 +121,7 @@ type Config struct { // If true, launch a preemptible instance. Preemptible bool `mapstructure:"preemptible" required:"false"` // The time to wait for instance state changes. Defaults to "5m". - RawStateTimeout string `mapstructure:"state_timeout" required:"false"` + StateTimeout time.Duration `mapstructure:"state_timeout" required:"false"` // The region in which to launch the instance. Defaults to the region // hosting the specified zone. Region string `mapstructure:"region" required:"false"` @@ -183,7 +183,6 @@ type Config struct { Zone string `mapstructure:"zone" required:"true"` account *jwt.Config - stateTimeout time.Duration imageAlreadyExists bool ctx interpolate.Context } @@ -293,8 +292,8 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { c.MachineType = "n1-standard-1" } - if c.RawStateTimeout == "" { - c.RawStateTimeout = "5m" + if c.StateTimeout == 0 { + c.StateTimeout = 5 * time.Minute } if es := c.Comm.Prepare(&c.ctx); len(es) > 0 { @@ -330,11 +329,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { c.Region = region } - err = c.CalcTimeout() - if err != nil { - errs = packer.MultiErrorAppend(errs, err) - } - // Authenticating via an account file if c.AccountFile != "" { if c.VaultGCPOauthEngine != "" { @@ -384,15 +378,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { return c, nil, nil } -func (c *Config) CalcTimeout() error { - stateTimeout, err := time.ParseDuration(c.RawStateTimeout) - if err != nil { - return fmt.Errorf("Failed parsing state_timeout: %s", err) - } - c.stateTimeout = stateTimeout - return nil -} - type CustomerEncryptionKey struct { // KmsKeyName: The name of the encryption key that is stored in Google // Cloud KMS. diff --git a/builder/googlecompute/config.hcl2spec.go b/builder/googlecompute/config.hcl2spec.go index 3f2e62d09..cfa169a02 100644 --- a/builder/googlecompute/config.hcl2spec.go +++ b/builder/googlecompute/config.hcl2spec.go @@ -82,7 +82,7 @@ type FlatConfig struct { OmitExternalIP *bool `mapstructure:"omit_external_ip" required:"false" cty:"omit_external_ip"` OnHostMaintenance *string `mapstructure:"on_host_maintenance" required:"false" cty:"on_host_maintenance"` Preemptible *bool `mapstructure:"preemptible" required:"false" cty:"preemptible"` - RawStateTimeout *string `mapstructure:"state_timeout" required:"false" cty:"state_timeout"` + StateTimeout *string `mapstructure:"state_timeout" required:"false" cty:"state_timeout"` Region *string `mapstructure:"region" required:"false" cty:"region"` Scopes []string `mapstructure:"scopes" required:"false" cty:"scopes"` ServiceAccountEmail *string `mapstructure:"service_account_email" required:"false" cty:"service_account_email"` diff --git a/builder/googlecompute/step_create_image.go b/builder/googlecompute/step_create_image.go index 389338c43..62106d60b 100644 --- a/builder/googlecompute/step_create_image.go +++ b/builder/googlecompute/step_create_image.go @@ -44,7 +44,7 @@ func (s *StepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul var err error select { case err = <-errCh: - case <-time.After(config.stateTimeout): + case <-time.After(config.StateTimeout): err = errors.New("time out while waiting for image to register") } diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index 6004c2fab..ca15eeccb 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -154,7 +154,7 @@ func (s *StepCreateInstance) Run(ctx context.Context, state multistep.StateBag) ui.Message("Waiting for creation operation to complete...") select { case err = <-errCh: - case <-time.After(c.stateTimeout): + case <-time.After(c.StateTimeout): err = errors.New("time out while waiting for instance to create") } } @@ -200,7 +200,7 @@ func (s *StepCreateInstance) Cleanup(state multistep.StateBag) { if err == nil { select { case err = <-errCh: - case <-time.After(config.stateTimeout): + case <-time.After(config.StateTimeout): err = errors.New("time out while waiting for instance to delete") } } @@ -222,7 +222,7 @@ func (s *StepCreateInstance) Cleanup(state multistep.StateBag) { if err == nil { select { case err = <-errCh: - case <-time.After(config.stateTimeout): + case <-time.After(config.StateTimeout): err = errors.New("time out while waiting for disk to delete") } } diff --git a/builder/googlecompute/step_create_instance_test.go b/builder/googlecompute/step_create_instance_test.go index 33f0371fb..c107f4530 100644 --- a/builder/googlecompute/step_create_instance_test.go +++ b/builder/googlecompute/step_create_instance_test.go @@ -232,7 +232,7 @@ func TestStepCreateInstance_errorTimeout(t *testing.T) { errCh := make(chan error, 1) config := state.Get("config").(*Config) - config.stateTimeout = 1 * time.Microsecond + config.StateTimeout = 1 * time.Millisecond d := state.Get("driver").(*DriverMock) d.RunInstanceErrCh = errCh diff --git a/builder/googlecompute/step_create_windows_password.go b/builder/googlecompute/step_create_windows_password.go index a5ddb5950..2112b843c 100644 --- a/builder/googlecompute/step_create_windows_password.go +++ b/builder/googlecompute/step_create_windows_password.go @@ -99,7 +99,7 @@ func (s *StepCreateWindowsPassword) Run(ctx context.Context, state multistep.Sta ui.Message("Waiting for windows password to complete...") select { case err = <-errCh: - case <-time.After(c.stateTimeout): + case <-time.After(c.StateTimeout): err = errors.New("time out while waiting for the password to be created") } } diff --git a/builder/googlecompute/step_instance_info.go b/builder/googlecompute/step_instance_info.go index 1809fbb84..b36d2f1d8 100644 --- a/builder/googlecompute/step_instance_info.go +++ b/builder/googlecompute/step_instance_info.go @@ -29,7 +29,7 @@ func (s *StepInstanceInfo) Run(ctx context.Context, state multistep.StateBag) mu var err error select { case err = <-errCh: - case <-time.After(config.stateTimeout): + case <-time.After(config.StateTimeout): err = errors.New("time out while waiting for instance to become running") } diff --git a/builder/googlecompute/step_instance_info_test.go b/builder/googlecompute/step_instance_info_test.go index e3d0febaf..7435df7fc 100644 --- a/builder/googlecompute/step_instance_info_test.go +++ b/builder/googlecompute/step_instance_info_test.go @@ -156,7 +156,7 @@ func TestStepInstanceInfo_errorTimeout(t *testing.T) { state.Put("instance_name", "foo") config := state.Get("config").(*Config) - config.stateTimeout = 1 * time.Microsecond + config.StateTimeout = 1 * time.Millisecond driver := state.Get("driver").(*DriverMock) driver.WaitForInstanceErrCh = errCh diff --git a/builder/googlecompute/step_teardown_instance.go b/builder/googlecompute/step_teardown_instance.go index c992dead3..e7757862b 100644 --- a/builder/googlecompute/step_teardown_instance.go +++ b/builder/googlecompute/step_teardown_instance.go @@ -34,7 +34,7 @@ func (s *StepTeardownInstance) Run(ctx context.Context, state multistep.StateBag if err == nil { select { case err = <-errCh: - case <-time.After(config.stateTimeout): + case <-time.After(config.StateTimeout): err = errors.New("time out while waiting for instance to delete") } } @@ -64,7 +64,7 @@ func (s *StepTeardownInstance) Cleanup(state multistep.StateBag) { if err == nil { select { case err = <-errCh: - case <-time.After(config.stateTimeout): + case <-time.After(config.StateTimeout): err = errors.New("time out while waiting for disk to delete") } } diff --git a/builder/hcloud/config.go b/builder/hcloud/config.go index 73687ba5e..6e8b56ba6 100644 --- a/builder/hcloud/config.go +++ b/builder/hcloud/config.go @@ -23,8 +23,9 @@ type Config struct { common.PackerConfig `mapstructure:",squash"` Comm communicator.Config `mapstructure:",squash"` - HCloudToken string `mapstructure:"token"` - Endpoint string `mapstructure:"endpoint"` + HCloudToken string `mapstructure:"token"` + Endpoint string `mapstructure:"endpoint"` + PollInterval time.Duration `mapstructure:"poll_interval"` ServerName string `mapstructure:"server_name"` diff --git a/builder/hyperv/iso/builder.hcl2spec.go b/builder/hyperv/iso/builder.hcl2spec.go index e16785646..09f3fa0d3 100644 --- a/builder/hyperv/iso/builder.hcl2spec.go +++ b/builder/hyperv/iso/builder.hcl2spec.go @@ -26,10 +26,9 @@ type FlatConfig struct { ISOUrls []string `mapstructure:"iso_urls" cty:"iso_urls"` TargetPath *string `mapstructure:"iso_target_path" cty:"iso_target_path"` TargetExtension *string `mapstructure:"iso_target_extension" cty:"iso_target_extension"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` OutputDir *string `mapstructure:"output_directory" required:"false" cty:"output_directory"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` @@ -99,7 +98,7 @@ type FlatConfig struct { SkipExport *bool `mapstructure:"skip_export" required:"false" cty:"skip_export"` Headless *bool `mapstructure:"headless" required:"false" cty:"headless"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` DiskSize *uint `mapstructure:"disk_size" required:"false" cty:"disk_size"` UseLegacyNetworkAdapter *bool `mapstructure:"use_legacy_network_adapter" required:"false" cty:"use_legacy_network_adapter"` DifferencingDisk *bool `mapstructure:"differencing_disk" required:"false" cty:"differencing_disk"` @@ -135,7 +134,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "output_directory": &hcldec.AttrSpec{Name: "output_directory", Type: cty.String, Required: false}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, diff --git a/builder/hyperv/vmcx/builder.hcl2spec.go b/builder/hyperv/vmcx/builder.hcl2spec.go index 44971c8cb..1ba1e83ee 100644 --- a/builder/hyperv/vmcx/builder.hcl2spec.go +++ b/builder/hyperv/vmcx/builder.hcl2spec.go @@ -26,10 +26,9 @@ type FlatConfig struct { ISOUrls []string `mapstructure:"iso_urls" cty:"iso_urls"` TargetPath *string `mapstructure:"iso_target_path" cty:"iso_target_path"` TargetExtension *string `mapstructure:"iso_target_extension" cty:"iso_target_extension"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` OutputDir *string `mapstructure:"output_directory" required:"false" cty:"output_directory"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` @@ -99,7 +98,7 @@ type FlatConfig struct { SkipExport *bool `mapstructure:"skip_export" required:"false" cty:"skip_export"` Headless *bool `mapstructure:"headless" required:"false" cty:"headless"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` CloneFromVMCXPath *string `mapstructure:"clone_from_vmcx_path" cty:"clone_from_vmcx_path"` CloneFromVMName *string `mapstructure:"clone_from_vm_name" cty:"clone_from_vm_name"` CloneFromSnapshotName *string `mapstructure:"clone_from_snapshot_name" required:"false" cty:"clone_from_snapshot_name"` @@ -137,7 +136,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "output_directory": &hcldec.AttrSpec{Name: "output_directory", Type: cty.String, Required: false}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, diff --git a/builder/linode/builder_test.go b/builder/linode/builder_test.go index 918be6b2c..c80d1c76c 100644 --- a/builder/linode/builder_test.go +++ b/builder/linode/builder_test.go @@ -151,43 +151,6 @@ func TestBuilderPrepare_Image(t *testing.T) { } } -func TestBuilderPrepare_StateTimeout(t *testing.T) { - var b Builder - config := testConfig() - - // Test default - warnings, err := b.Prepare(config) - if len(warnings) > 0 { - t.Fatalf("bad: %#v", warnings) - } - if err != nil { - t.Fatalf("should not have error: %s", err) - } - - // Test set - config["state_timeout"] = "5m" - b = Builder{} - warnings, err = b.Prepare(config) - if len(warnings) > 0 { - t.Fatalf("bad: %#v", warnings) - } - if err != nil { - t.Fatalf("should not have error: %s", err) - } - - // Test bad - config["state_timeout"] = "tubes" - b = Builder{} - warnings, err = b.Prepare(config) - if len(warnings) > 0 { - t.Fatalf("bad: %#v", warnings) - } - if err == nil { - t.Fatal("should have error") - } - -} - func TestBuilderPrepare_ImageLabel(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/linode/config.go b/builder/linode/config.go index df6346c9c..ea8eac073 100644 --- a/builder/linode/config.go +++ b/builder/linode/config.go @@ -9,7 +9,6 @@ import ( "fmt" "os" "regexp" - "time" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/communicator" @@ -36,10 +35,7 @@ type Config struct { ImageLabel string `mapstructure:"image_label"` Description string `mapstructure:"image_description"` - RawStateTimeout string `mapstructure:"state_timeout"` - - stateTimeout time.Duration - interCtx interpolate.Context + interCtx interpolate.Context } func createRandomRootPassword() (string, error) { @@ -101,16 +97,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { } } - if c.RawStateTimeout == "" { - c.stateTimeout = 5 * time.Minute - } else { - if stateTimeout, err := time.ParseDuration(c.RawStateTimeout); err == nil { - c.stateTimeout = stateTimeout - } else { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to parse state timeout: %s", err)) - } - } - if es := c.Comm.Prepare(&c.ctx); len(es) > 0 { errs = packer.MultiErrorAppend(errs, es...) } diff --git a/builder/linode/config.hcl2spec.go b/builder/linode/config.hcl2spec.go index 9fc15340e..e22bc7507 100644 --- a/builder/linode/config.hcl2spec.go +++ b/builder/linode/config.hcl2spec.go @@ -67,7 +67,6 @@ type FlatConfig struct { RootSSHKey *string `mapstructure:"root_ssh_key" cty:"root_ssh_key"` ImageLabel *string `mapstructure:"image_label" cty:"image_label"` Description *string `mapstructure:"image_description" cty:"image_description"` - RawStateTimeout *string `mapstructure:"state_timeout" cty:"state_timeout"` } // FlatMapstructure returns a new FlatConfig. @@ -137,7 +136,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "root_ssh_key": &hcldec.AttrSpec{Name: "root_ssh_key", Type: cty.String, Required: false}, "image_label": &hcldec.AttrSpec{Name: "image_label", Type: cty.String, Required: false}, "image_description": &hcldec.AttrSpec{Name: "image_description", Type: cty.String, Required: false}, - "state_timeout": &hcldec.AttrSpec{Name: "state_timeout", Type: cty.String, Required: false}, } return s } diff --git a/builder/lxc/config.go b/builder/lxc/config.go index d5fa44ed3..587e205a0 100644 --- a/builder/lxc/config.go +++ b/builder/lxc/config.go @@ -31,7 +31,8 @@ type Config struct { CommandWrapper string `mapstructure:"command_wrapper" required:"false"` // The timeout in seconds to wait for the the // container to start. Defaults to 20 seconds. - RawInitTimeout string `mapstructure:"init_timeout" required:"false"` + InitTimeout time.Duration `mapstructure:"init_timeout" required:"false"` + // Options to pass to lxc-create. For // instance, you can specify a custom LXC container configuration file with // ["-f", "/path/to/lxc.conf"]. Defaults to []. See man 1 lxc-create for @@ -62,7 +63,6 @@ type Config struct { // container to reach. Note some distributions (Ubuntu) simulate run levels // and may report 5 rather than 3. TargetRunlevel int `mapstructure:"target_runlevel" required:"false"` - InitTimeout time.Duration ctx interpolate.Context } @@ -98,13 +98,8 @@ func NewConfig(raws ...interface{}) (*Config, error) { c.CommandWrapper = "{{.Command}}" } - if c.RawInitTimeout == "" { - c.RawInitTimeout = "20s" - } - - c.InitTimeout, err = time.ParseDuration(c.RawInitTimeout) - if err != nil { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("Failed parsing init_timeout: %s", err)) + if c.InitTimeout == 0 { + c.InitTimeout = 20 * time.Second } if _, err := os.Stat(c.ConfigFile); os.IsNotExist(err) { diff --git a/builder/parallels/iso/builder.hcl2spec.go b/builder/parallels/iso/builder.hcl2spec.go index 73f4aefe5..e8e6e506c 100644 --- a/builder/parallels/iso/builder.hcl2spec.go +++ b/builder/parallels/iso/builder.hcl2spec.go @@ -29,10 +29,9 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` OutputDir *string `mapstructure:"output_directory" required:"false" cty:"output_directory"` CpuCount *int `mapstructure:"cpus" required:"false" cty:"cpus"` MemorySize *int `mapstructure:"memory" required:"false" cty:"memory"` @@ -42,7 +41,7 @@ type FlatConfig struct { PrlctlPost [][]string `mapstructure:"prlctl_post" required:"false" cty:"prlctl_post"` PrlctlVersionFile *string `mapstructure:"prlctl_version_file" required:"false" cty:"prlctl_version_file"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -128,7 +127,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "output_directory": &hcldec.AttrSpec{Name: "output_directory", Type: cty.String, Required: false}, "cpus": &hcldec.AttrSpec{Name: "cpus", Type: cty.Number, Required: false}, "memory": &hcldec.AttrSpec{Name: "memory", Type: cty.Number, Required: false}, diff --git a/builder/parallels/pvm/config.hcl2spec.go b/builder/parallels/pvm/config.hcl2spec.go index b0a1f90a4..77d76625f 100644 --- a/builder/parallels/pvm/config.hcl2spec.go +++ b/builder/parallels/pvm/config.hcl2spec.go @@ -65,11 +65,10 @@ type FlatConfig struct { WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm"` SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` ParallelsToolsFlavor *string `mapstructure:"parallels_tools_flavor" required:"true" cty:"parallels_tools_flavor"` ParallelsToolsGuestPath *string `mapstructure:"parallels_tools_guest_path" required:"false" cty:"parallels_tools_guest_path"` ParallelsToolsMode *string `mapstructure:"parallels_tools_mode" required:"false" cty:"parallels_tools_mode"` @@ -148,7 +147,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "parallels_tools_flavor": &hcldec.AttrSpec{Name: "parallels_tools_flavor", Type: cty.String, Required: false}, "parallels_tools_guest_path": &hcldec.AttrSpec{Name: "parallels_tools_guest_path", Type: cty.String, Required: false}, "parallels_tools_mode": &hcldec.AttrSpec{Name: "parallels_tools_mode", Type: cty.String, Required: false}, diff --git a/builder/proxmox/config.go b/builder/proxmox/config.go index d4deead65..b3c08ecaf 100644 --- a/builder/proxmox/config.go +++ b/builder/proxmox/config.go @@ -24,8 +24,7 @@ type Config struct { common.PackerConfig `mapstructure:",squash"` common.HTTPConfig `mapstructure:",squash"` bootcommand.BootConfig `mapstructure:",squash"` - RawBootKeyInterval string `mapstructure:"boot_key_interval"` - BootKeyInterval time.Duration `` + BootKeyInterval time.Duration `mapstructure:"boot_key_interval"` Comm communicator.Config `mapstructure:",squash"` ProxmoxURLRaw string `mapstructure:"proxmox_url"` @@ -104,18 +103,16 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { if c.Password == "" { c.Password = os.Getenv("PROXMOX_PASSWORD") } - if c.RawBootKeyInterval == "" { - c.RawBootKeyInterval = os.Getenv(common.PackerKeyEnv) - } - if c.RawBootKeyInterval == "" { - c.BootKeyInterval = 5 * time.Millisecond - } else { - if interval, err := time.ParseDuration(c.RawBootKeyInterval); err == nil { - c.BootKeyInterval = interval - } else { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("Could not parse boot_key_interval: %v", err)) + if c.BootKeyInterval == 0 && os.Getenv(common.PackerKeyEnv) != "" { + var err error + c.BootKeyInterval, err = time.ParseDuration(os.Getenv(common.PackerKeyEnv)) + if err != nil { + errs = packer.MultiErrorAppend(errs, err) } } + if c.BootKeyInterval == 0 { + c.BootKeyInterval = 5 * time.Millisecond + } if c.VMName == "" { // Default to packer-[time-ordered-uuid] diff --git a/builder/proxmox/config.hcl2spec.go b/builder/proxmox/config.hcl2spec.go index a8cc2c0f0..797bf117b 100644 --- a/builder/proxmox/config.hcl2spec.go +++ b/builder/proxmox/config.hcl2spec.go @@ -19,11 +19,10 @@ type FlatConfig struct { HTTPDir *string `mapstructure:"http_directory" cty:"http_directory"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` - RawBootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` + BootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -109,7 +108,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "boot_key_interval": &hcldec.AttrSpec{Name: "boot_key_interval", Type: cty.String, Required: false}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, diff --git a/builder/proxmox/step_type_boot_command.go b/builder/proxmox/step_type_boot_command.go index 97cb70c54..d40e13056 100644 --- a/builder/proxmox/step_type_boot_command.go +++ b/builder/proxmox/step_type_boot_command.go @@ -47,7 +47,7 @@ func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) } if int64(s.BootWait) > 0 { - ui.Say(fmt.Sprintf("Waiting %s for boot", s.BootWait.String())) + ui.Say(fmt.Sprintf("Waiting %s for boot", s.BootWait)) select { case <-time.After(s.BootWait): break diff --git a/builder/qemu/builder.hcl2spec.go b/builder/qemu/builder.hcl2spec.go index 4675ba834..84697974b 100644 --- a/builder/qemu/builder.hcl2spec.go +++ b/builder/qemu/builder.hcl2spec.go @@ -26,14 +26,13 @@ type FlatConfig struct { ISOUrls []string `mapstructure:"iso_urls" cty:"iso_urls"` TargetPath *string `mapstructure:"iso_target_path" cty:"iso_target_path"` TargetExtension *string `mapstructure:"iso_target_extension" cty:"iso_target_extension"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` DisableVNC *bool `mapstructure:"disable_vnc" cty:"disable_vnc"` - RawBootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` + BootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -141,7 +140,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "disable_vnc": &hcldec.AttrSpec{Name: "disable_vnc", Type: cty.Bool, Required: false}, "boot_key_interval": &hcldec.AttrSpec{Name: "boot_key_interval", Type: cty.String, Required: false}, "shutdown_command": &hcldec.AttrSpec{Name: "shutdown_command", Type: cty.String, Required: false}, diff --git a/builder/qemu/step_type_boot_command.go b/builder/qemu/step_type_boot_command.go index 4bce10d0c..c6aa09ea2 100644 --- a/builder/qemu/step_type_boot_command.go +++ b/builder/qemu/step_type_boot_command.go @@ -51,7 +51,7 @@ func (s *stepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) // Wait the for the vm to boot. if int64(config.BootWait) > 0 { - ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait.String())) + ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait)) select { case <-time.After(config.BootWait): break diff --git a/builder/vagrant/builder.hcl2spec.go b/builder/vagrant/builder.hcl2spec.go index 710a6ad3b..1a9dece69 100644 --- a/builder/vagrant/builder.hcl2spec.go +++ b/builder/vagrant/builder.hcl2spec.go @@ -29,10 +29,9 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -130,7 +129,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, "ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false}, diff --git a/builder/virtualbox/common/shutdown_config.go b/builder/virtualbox/common/shutdown_config.go index 63b58d8a5..5dd70c69b 100644 --- a/builder/virtualbox/common/shutdown_config.go +++ b/builder/virtualbox/common/shutdown_config.go @@ -3,7 +3,6 @@ package common import ( - "fmt" "time" "github.com/hashicorp/packer/template/interpolate" @@ -22,37 +21,18 @@ type ShutdownConfig struct { // shutdown_command for the virtual machine to actually shut down. If it // doesn't shut down in this time, it is an error. By default, the timeout is // 5m or five minutes. - RawShutdownTimeout string `mapstructure:"shutdown_timeout" required:"false"` + ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" required:"false"` // The amount of time to wait after shutting // down the virtual machine. If you get the error // Error removing floppy controller, you might need to set this to 5m // or so. By default, the delay is 0s or disabled. - RawPostShutdownDelay string `mapstructure:"post_shutdown_delay" required:"false"` - - ShutdownTimeout time.Duration `` - PostShutdownDelay time.Duration `` + PostShutdownDelay time.Duration `mapstructure:"post_shutdown_delay" required:"false"` } func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error { - if c.RawShutdownTimeout == "" { - c.RawShutdownTimeout = "5m" + if c.ShutdownTimeout == 0 { + c.ShutdownTimeout = 5 * time.Minute } - if c.RawPostShutdownDelay == "" { - c.RawPostShutdownDelay = "0s" - } - - var errs []error - var err error - c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout) - if err != nil { - errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err)) - } - - c.PostShutdownDelay, err = time.ParseDuration(c.RawPostShutdownDelay) - if err != nil { - errs = append(errs, fmt.Errorf("Failed parsing post_shutdown_delay: %s", err)) - } - - return errs + return nil } diff --git a/builder/virtualbox/common/shutdown_config_test.go b/builder/virtualbox/common/shutdown_config_test.go index 897e673bc..206e2f848 100644 --- a/builder/virtualbox/common/shutdown_config_test.go +++ b/builder/virtualbox/common/shutdown_config_test.go @@ -26,17 +26,9 @@ func TestShutdownConfigPrepare_ShutdownTimeout(t *testing.T) { var c *ShutdownConfig var errs []error - // Test with a bad value - c = testShutdownConfig() - c.RawShutdownTimeout = "this is not good" - errs = c.Prepare(interpolate.NewContext()) - if len(errs) == 0 { - t.Fatalf("should have error") - } - // Test with a good one c = testShutdownConfig() - c.RawShutdownTimeout = "5s" + c.ShutdownTimeout = 5 * time.Second errs = c.Prepare(interpolate.NewContext()) if len(errs) > 0 { t.Fatalf("err: %#v", errs) @@ -50,17 +42,9 @@ func TestShutdownConfigPrepare_PostShutdownDelay(t *testing.T) { var c *ShutdownConfig var errs []error - // Test with a bad value - c = testShutdownConfig() - c.RawPostShutdownDelay = "this is not good" - errs = c.Prepare(interpolate.NewContext()) - if len(errs) == 0 { - t.Fatalf("should have error") - } - // Test with default value c = testShutdownConfig() - c.RawPostShutdownDelay = "" + c.PostShutdownDelay = 0 errs = c.Prepare(interpolate.NewContext()) if len(errs) > 0 { t.Fatalf("err: %#v", errs) @@ -71,12 +55,12 @@ func TestShutdownConfigPrepare_PostShutdownDelay(t *testing.T) { // Test with a good one c = testShutdownConfig() - c.RawPostShutdownDelay = "5s" + c.PostShutdownDelay = 5 * time.Millisecond errs = c.Prepare(interpolate.NewContext()) if len(errs) > 0 { t.Fatalf("err: %#v", errs) } - if c.PostShutdownDelay != 5*time.Second { + if c.PostShutdownDelay != 5*time.Millisecond { t.Fatalf("bad: %s", c.PostShutdownDelay) } } diff --git a/builder/virtualbox/iso/builder.hcl2spec.go b/builder/virtualbox/iso/builder.hcl2spec.go index af6d5027f..2eb36629e 100644 --- a/builder/virtualbox/iso/builder.hcl2spec.go +++ b/builder/virtualbox/iso/builder.hcl2spec.go @@ -29,10 +29,9 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` Format *string `mapstructure:"format" required:"false" cty:"format"` ExportOpts []string `mapstructure:"export_opts" required:"false" cty:"export_opts"` OutputDir *string `mapstructure:"output_directory" required:"false" cty:"output_directory"` @@ -41,8 +40,8 @@ type FlatConfig struct { VRDPPortMin *int `mapstructure:"vrdp_port_min" required:"false" cty:"vrdp_port_min"` VRDPPortMax *int `mapstructure:"vrdp_port_max" cty:"vrdp_port_max"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` - RawPostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + PostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -144,7 +143,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "format": &hcldec.AttrSpec{Name: "format", Type: cty.String, Required: false}, "export_opts": &hcldec.AttrSpec{Name: "export_opts", Type: cty.List(cty.String), Required: false}, "output_directory": &hcldec.AttrSpec{Name: "output_directory", Type: cty.String, Required: false}, diff --git a/builder/virtualbox/ovf/config.hcl2spec.go b/builder/virtualbox/ovf/config.hcl2spec.go index ba709eba1..789b147a1 100644 --- a/builder/virtualbox/ovf/config.hcl2spec.go +++ b/builder/virtualbox/ovf/config.hcl2spec.go @@ -22,10 +22,9 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` Format *string `mapstructure:"format" required:"false" cty:"format"` ExportOpts []string `mapstructure:"export_opts" required:"false" cty:"export_opts"` OutputDir *string `mapstructure:"output_directory" required:"false" cty:"output_directory"` @@ -78,8 +77,8 @@ type FlatConfig struct { SSHSkipNatMapping *bool `mapstructure:"ssh_skip_nat_mapping" required:"false" cty:"ssh_skip_nat_mapping"` SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` - RawPostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + PostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"` VBoxManage [][]string `mapstructure:"vboxmanage" required:"false" cty:"vboxmanage"` VBoxManagePost [][]string `mapstructure:"vboxmanage_post" required:"false" cty:"vboxmanage_post"` VBoxVersionFile *string `mapstructure:"virtualbox_version_file" required:"false" cty:"virtualbox_version_file"` @@ -124,7 +123,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "format": &hcldec.AttrSpec{Name: "format", Type: cty.String, Required: false}, "export_opts": &hcldec.AttrSpec{Name: "export_opts", Type: cty.List(cty.String), Required: false}, "output_directory": &hcldec.AttrSpec{Name: "output_directory", Type: cty.String, Required: false}, diff --git a/builder/virtualbox/vm/config.go b/builder/virtualbox/vm/config.go index e43d44283..14b57295d 100644 --- a/builder/virtualbox/vm/config.go +++ b/builder/virtualbox/vm/config.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "strings" + "time" vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common" "github.com/hashicorp/packer/common" @@ -71,8 +72,8 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { c.GuestAdditionsPath = "VBoxGuestAdditions.iso" } - if c.RawPostShutdownDelay == "" { - c.RawPostShutdownDelay = "2s" + if c.PostShutdownDelay == 0 { + c.PostShutdownDelay = 2 * time.Second } // Prepare the errors @@ -88,7 +89,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs = packer.MultiErrorAppend(errs, c.VBoxVersionConfig.Prepare(&c.ctx)...) errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...) - log.Printf("PostShutdownDelay: %f", c.PostShutdownDelay.Seconds()) + log.Printf("PostShutdownDelay: %s", c.PostShutdownDelay) if c.VMName == "" { errs = packer.MultiErrorAppend(errs, diff --git a/builder/virtualbox/vm/config.hcl2spec.go b/builder/virtualbox/vm/config.hcl2spec.go index 0214aac6a..da231ce2c 100644 --- a/builder/virtualbox/vm/config.hcl2spec.go +++ b/builder/virtualbox/vm/config.hcl2spec.go @@ -22,10 +22,9 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` Format *string `mapstructure:"format" required:"false" cty:"format"` ExportOpts []string `mapstructure:"export_opts" required:"false" cty:"export_opts"` OutputDir *string `mapstructure:"output_directory" required:"false" cty:"output_directory"` @@ -78,8 +77,8 @@ type FlatConfig struct { SSHSkipNatMapping *bool `mapstructure:"ssh_skip_nat_mapping" required:"false" cty:"ssh_skip_nat_mapping"` SSHWaitTimeout *string `mapstructure:"ssh_wait_timeout" cty:"ssh_wait_timeout"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` - RawPostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + PostShutdownDelay *string `mapstructure:"post_shutdown_delay" required:"false" cty:"post_shutdown_delay"` VBoxManage [][]string `mapstructure:"vboxmanage" required:"false" cty:"vboxmanage"` VBoxManagePost [][]string `mapstructure:"vboxmanage_post" required:"false" cty:"vboxmanage_post"` VBoxVersionFile *string `mapstructure:"virtualbox_version_file" required:"false" cty:"virtualbox_version_file"` @@ -120,7 +119,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "format": &hcldec.AttrSpec{Name: "format", Type: cty.String, Required: false}, "export_opts": &hcldec.AttrSpec{Name: "export_opts", Type: cty.List(cty.String), Required: false}, "output_directory": &hcldec.AttrSpec{Name: "output_directory", Type: cty.String, Required: false}, diff --git a/builder/vmware/iso/config.hcl2spec.go b/builder/vmware/iso/config.hcl2spec.go index 9a5da2aae..6dce149ae 100644 --- a/builder/vmware/iso/config.hcl2spec.go +++ b/builder/vmware/iso/config.hcl2spec.go @@ -29,12 +29,11 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` DisableVNC *bool `mapstructure:"disable_vnc" cty:"disable_vnc"` - RawBootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` + BootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` FusionAppPath *string `mapstructure:"fusion_app_path" required:"false" cty:"fusion_app_path"` RemoteType *string `mapstructure:"remote_type" required:"false" cty:"remote_type"` RemoteDatastore *string `mapstructure:"remote_datastore" required:"false" cty:"remote_datastore"` @@ -62,7 +61,7 @@ type FlatConfig struct { VNCPortMax *int `mapstructure:"vnc_port_max" cty:"vnc_port_max"` VNCDisablePassword *bool `mapstructure:"vnc_disable_password" required:"false" cty:"vnc_disable_password"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -161,7 +160,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "disable_vnc": &hcldec.AttrSpec{Name: "disable_vnc", Type: cty.Bool, Required: false}, "boot_key_interval": &hcldec.AttrSpec{Name: "boot_key_interval", Type: cty.String, Required: false}, "fusion_app_path": &hcldec.AttrSpec{Name: "fusion_app_path", Type: cty.String, Required: false}, diff --git a/builder/vmware/vmx/config.hcl2spec.go b/builder/vmware/vmx/config.hcl2spec.go index 432837e07..15fc44b5e 100644 --- a/builder/vmware/vmx/config.hcl2spec.go +++ b/builder/vmware/vmx/config.hcl2spec.go @@ -22,12 +22,11 @@ type FlatConfig struct { FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label"` - RawBootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` - RawBootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` + BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval"` + BootWait *string `mapstructure:"boot_wait" cty:"boot_wait"` BootCommand []string `mapstructure:"boot_command" cty:"boot_command"` - BootGroupInterval *string `cty:"boot_group_interval"` DisableVNC *bool `mapstructure:"disable_vnc" cty:"disable_vnc"` - RawBootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` + BootKeyInterval *string `mapstructure:"boot_key_interval" cty:"boot_key_interval"` FusionAppPath *string `mapstructure:"fusion_app_path" required:"false" cty:"fusion_app_path"` RemoteType *string `mapstructure:"remote_type" required:"false" cty:"remote_type"` RemoteDatastore *string `mapstructure:"remote_datastore" required:"false" cty:"remote_datastore"` @@ -46,7 +45,7 @@ type FlatConfig struct { VNCPortMax *int `mapstructure:"vnc_port_max" cty:"vnc_port_max"` VNCDisablePassword *bool `mapstructure:"vnc_disable_password" required:"false" cty:"vnc_disable_password"` ShutdownCommand *string `mapstructure:"shutdown_command" required:"false" cty:"shutdown_command"` - RawShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` + ShutdownTimeout *string `mapstructure:"shutdown_timeout" required:"false" cty:"shutdown_timeout"` Type *string `mapstructure:"communicator" cty:"communicator"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host"` @@ -130,7 +129,6 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, "boot_wait": &hcldec.AttrSpec{Name: "boot_wait", Type: cty.String, Required: false}, "boot_command": &hcldec.AttrSpec{Name: "boot_command", Type: cty.List(cty.String), Required: false}, - "boot_group_interval": &hcldec.AttrSpec{Name: "boot_group_interval", Type: cty.String, Required: false}, "disable_vnc": &hcldec.AttrSpec{Name: "disable_vnc", Type: cty.Bool, Required: false}, "boot_key_interval": &hcldec.AttrSpec{Name: "boot_key_interval", Type: cty.String, Required: false}, "fusion_app_path": &hcldec.AttrSpec{Name: "fusion_app_path", Type: cty.String, Required: false}, diff --git a/cmd/struct-markdown/main.go b/cmd/struct-markdown/main.go index ccf80b47c..9d0bf3a5b 100644 --- a/cmd/struct-markdown/main.go +++ b/cmd/struct-markdown/main.go @@ -111,6 +111,10 @@ func main() { } fieldType := string(b[field.Type.Pos()-1 : field.Type.End()-1]) fieldType = strings.ReplaceAll(fieldType, "*", `\*`) + switch fieldType { + case "time.Duration": + fieldType = `duration string | ex: "1h5m2s"` + } field := Field{ Name: name, diff --git a/common/bootcommand/config.go b/common/bootcommand/config.go index ddef4132f..607ee6f9e 100644 --- a/common/bootcommand/config.go +++ b/common/bootcommand/config.go @@ -112,21 +112,19 @@ type BootConfig struct { // Packer to wait five seconds and one minute 30 seconds, respectively. If // this isn't specified, a sensible default value is picked depending on // the builder type. - RawBootGroupInterval string `mapstructure:"boot_keygroup_interval"` + BootGroupInterval time.Duration `mapstructure:"boot_keygroup_interval"` // The time to wait after booting the initial virtual machine before typing // the `boot_command`. The value of this should be a duration. Examples are // `5s` and `1m30s` which will cause Packer to wait five seconds and one // minute 30 seconds, respectively. If this isn't specified, the default is // `10s` or 10 seconds. - RawBootWait string `mapstructure:"boot_wait"` + BootWait time.Duration `mapstructure:"boot_wait"` // This is an array of commands to type when the virtual machine is first // booted. The goal of these commands should be to type just enough to // initialize the operating system installer. Special keys can be typed as // well, and are covered in the section below on the boot command. If this // is not specified, it is assumed the installer will start itself. - BootCommand []string `mapstructure:"boot_command"` - BootGroupInterval time.Duration `` - BootWait time.Duration `` + BootCommand []string `mapstructure:"boot_command"` } // The boot command "typed" character for character over a VNC connection to @@ -142,37 +140,12 @@ type VNCConfig struct { // when this is true. Defaults to false. DisableVNC bool `mapstructure:"disable_vnc"` // Time in ms to wait between each key press - RawBootKeyInterval string `mapstructure:"boot_key_interval"` - BootKeyInterval time.Duration `` + BootKeyInterval time.Duration `mapstructure:"boot_key_interval"` } func (c *BootConfig) Prepare(ctx *interpolate.Context) (errs []error) { - if c.RawBootWait == "" { - c.RawBootWait = "10s" - } - - if c.RawBootWait != "" { - bw, err := time.ParseDuration(c.RawBootWait) - if err != nil { - errs = append( - errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) - } else { - c.BootWait = bw - } - } - - if c.RawBootGroupInterval == "" { - c.RawBootGroupInterval = "0ms" - } - - if c.RawBootGroupInterval != "" { - bgi, err := time.ParseDuration(c.RawBootGroupInterval) - if err != nil { - errs = append( - errs, fmt.Errorf("Failed parsing boot_keygroup_interval: %s", err)) - } else { - c.BootGroupInterval = bgi - } + if c.BootWait == 0 { + c.BootWait = 10 * time.Second } if c.BootCommand != nil { @@ -197,20 +170,6 @@ func (c *VNCConfig) Prepare(ctx *interpolate.Context) (errs []error) { fmt.Errorf("A boot command cannot be used when vnc is disabled.")) } - if c.RawBootKeyInterval == "" { - c.RawBootKeyInterval = "0ms" - } - - if c.RawBootKeyInterval != "" { - bki, err := time.ParseDuration(c.RawBootKeyInterval) - if err != nil { - errs = append( - errs, fmt.Errorf("Failed parsing boot_key_interval: %s", err)) - } else { - c.BootKeyInterval = bki - } - } - errs = append(errs, c.BootConfig.Prepare(ctx)...) return } diff --git a/common/bootcommand/config_test.go b/common/bootcommand/config_test.go index 551f2c785..0f56e1c15 100644 --- a/common/bootcommand/config_test.go +++ b/common/bootcommand/config_test.go @@ -2,6 +2,7 @@ package bootcommand import ( "testing" + "time" "github.com/hashicorp/packer/template/interpolate" ) @@ -11,26 +12,18 @@ func TestConfigPrepare(t *testing.T) { // Test a default boot_wait c = new(BootConfig) - c.RawBootWait = "" + c.BootWait = 0 errs := c.Prepare(&interpolate.Context{}) if len(errs) > 0 { t.Fatalf("bad: %#v", errs) } - if c.RawBootWait != "10s" { - t.Fatalf("bad value: %s", c.RawBootWait) - } - - // Test with a bad boot_wait - c = new(BootConfig) - c.RawBootWait = "this is not good" - errs = c.Prepare(&interpolate.Context{}) - if len(errs) == 0 { - t.Fatal("should error") + if c.BootWait != 10*time.Second { + t.Fatalf("bad value: %s", c.BootWait) } // Test with a good one c = new(BootConfig) - c.RawBootWait = "5s" + c.BootWait = 5 * time.Second errs = c.Prepare(&interpolate.Context{}) if len(errs) > 0 { t.Fatalf("bad: %#v", errs) diff --git a/common/shutdowncommand/config.go b/common/shutdowncommand/config.go index a5198318e..efea7db8d 100644 --- a/common/shutdowncommand/config.go +++ b/common/shutdowncommand/config.go @@ -3,7 +3,6 @@ package shutdowncommand import ( - "fmt" "time" "github.com/hashicorp/packer/template/interpolate" @@ -23,22 +22,13 @@ type ShutdownConfig struct { // virtual machine to actually shut down. If the machine doesn't shut down // in this time it is considered an error. By default, the time out is "5m" // (five minutes). - RawShutdownTimeout string `mapstructure:"shutdown_timeout" required:"false"` - - ShutdownTimeout time.Duration `` + ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" required:"false"` } func (c *ShutdownConfig) Prepare(ctx *interpolate.Context) []error { - if c.RawShutdownTimeout == "" { - c.RawShutdownTimeout = "5m" + if c.ShutdownTimeout == 0 { + c.ShutdownTimeout = 5 * time.Minute } - var errs []error - var err error - c.ShutdownTimeout, err = time.ParseDuration(c.RawShutdownTimeout) - if err != nil { - errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err)) - } - - return errs + return nil } diff --git a/common/shutdowncommand/config_test.go b/common/shutdowncommand/config_test.go index 44ab632cb..ada363a2f 100644 --- a/common/shutdowncommand/config_test.go +++ b/common/shutdowncommand/config_test.go @@ -26,17 +26,9 @@ func TestShutdownConfigPrepare_ShutdownTimeout(t *testing.T) { var c *ShutdownConfig var errs []error - // Test with a bad value - c = testShutdownConfig() - c.RawShutdownTimeout = "this is not good" - errs = c.Prepare(interpolate.NewContext()) - if len(errs) == 0 { - t.Fatalf("should have error") - } - // Test with a good one c = testShutdownConfig() - c.RawShutdownTimeout = "5s" + c.ShutdownTimeout = 5 * time.Second errs = c.Prepare(interpolate.NewContext()) if len(errs) > 0 { t.Fatalf("err: %#v", errs) diff --git a/hcl2template/load_test.go b/hcl2template/load_test.go index c91893c8e..0f4d6f91d 100644 --- a/hcl2template/load_test.go +++ b/hcl2template/load_test.go @@ -80,7 +80,7 @@ func TestParser_ParseFile(t *testing.T) { RawSingleISOUrl: strPtr("http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso"), BootCommand: []string{"..."}, ShutdownCommand: strPtr("echo 'vagrant' | sudo -S shutdown -P now"), - RawBootWait: strPtr("10s"), + BootWait: strPtr("10s"), VBoxManage: [][]string{}, VBoxManagePost: [][]string{}, }, diff --git a/hcl2template/parser_test.go b/hcl2template/parser_test.go index c62bf6bdb..1056153d6 100644 --- a/hcl2template/parser_test.go +++ b/hcl2template/parser_test.go @@ -52,7 +52,7 @@ func TestParser_Parse(t *testing.T) { RawSingleISOUrl: strPtr("http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso"), BootCommand: []string{"..."}, ShutdownCommand: strPtr("echo 'vagrant' | sudo -S shutdown -P now"), - RawBootWait: strPtr("10s"), + BootWait: strPtr("10s"), VBoxManage: [][]string{}, VBoxManagePost: [][]string{}, }, diff --git a/helper/communicator/config.go b/helper/communicator/config.go index 20207d1c6..c6c5d880e 100644 --- a/helper/communicator/config.go +++ b/helper/communicator/config.go @@ -470,7 +470,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error { return errs } -func (c *Config) prepareWinRM(ctx *interpolate.Context) []error { +func (c *Config) prepareWinRM(ctx *interpolate.Context) (errs []error) { if c.WinRMPort == 0 && c.WinRMUseSSL { c.WinRMPort = 5986 } else if c.WinRMPort == 0 { @@ -485,7 +485,6 @@ func (c *Config) prepareWinRM(ctx *interpolate.Context) []error { c.WinRMTransportDecorator = func() winrm.Transporter { return &winrm.ClientNTLM{} } } - var errs []error if c.WinRMUser == "" { errs = append(errs, errors.New("winrm_username must be specified.")) } diff --git a/packer/core.go b/packer/core.go index bcdd91b30..cae4c39cc 100644 --- a/packer/core.go +++ b/packer/core.go @@ -135,12 +135,12 @@ func (c *Core) generateCoreBuildProvisioner(rawP *template.Provisioner, rawName } } // If we're pausing, we wrap the provisioner in a special pauser. - if rawP.PauseBefore > 0 { + if rawP.PauseBefore != 0 { provisioner = &PausedProvisioner{ PauseBefore: rawP.PauseBefore, Provisioner: provisioner, } - } else if rawP.Timeout > 0 { + } else if rawP.Timeout != 0 { provisioner = &TimeoutProvisioner{ Timeout: rawP.Timeout, Provisioner: provisioner, diff --git a/post-processor/digitalocean-import/post-processor.go b/post-processor/digitalocean-import/post-processor.go index 0588a3566..57e82f668 100644 --- a/post-processor/digitalocean-import/post-processor.go +++ b/post-processor/digitalocean-import/post-processor.go @@ -35,16 +35,17 @@ type Config struct { SpacesKey string `mapstructure:"spaces_key"` SpacesSecret string `mapstructure:"spaces_secret"` - SpacesRegion string `mapstructure:"spaces_region"` - SpaceName string `mapstructure:"space_name"` - ObjectName string `mapstructure:"space_object_name"` - SkipClean bool `mapstructure:"skip_clean"` - Tags []string `mapstructure:"image_tags"` - Name string `mapstructure:"image_name"` - Description string `mapstructure:"image_description"` - Distribution string `mapstructure:"image_distribution"` - ImageRegions []string `mapstructure:"image_regions"` - Timeout time.Duration `mapstructure:"timeout"` + SpacesRegion string `mapstructure:"spaces_region"` + SpaceName string `mapstructure:"space_name"` + ObjectName string `mapstructure:"space_object_name"` + SkipClean bool `mapstructure:"skip_clean"` + Tags []string `mapstructure:"image_tags"` + Name string `mapstructure:"image_name"` + Description string `mapstructure:"image_description"` + Distribution string `mapstructure:"image_distribution"` + ImageRegions []string `mapstructure:"image_regions"` + + Timeout time.Duration `mapstructure:"timeout"` ctx interpolate.Context } diff --git a/post-processor/googlecompute-export/post-processor.go b/post-processor/googlecompute-export/post-processor.go index eff848bdf..6183619a3 100644 --- a/post-processor/googlecompute-export/post-processor.go +++ b/post-processor/googlecompute-export/post-processor.go @@ -6,6 +6,7 @@ import ( "context" "fmt" "strings" + "time" "github.com/hashicorp/packer/builder/googlecompute" "github.com/hashicorp/packer/common" @@ -138,7 +139,7 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact Metadata: exporterMetadata, Network: p.config.Network, NetworkProjectId: builderProjectId, - RawStateTimeout: "5m", + StateTimeout: 5 * time.Minute, SourceImageFamily: "debian-9-worker", SourceImageProjectId: "compute-image-tools", Subnetwork: p.config.Subnetwork, @@ -149,7 +150,6 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact "https://www.googleapis.com/auth/userinfo.email", }, } - exporterConfig.CalcTimeout() driver, err := googlecompute.NewDriverGCE(ui, builderProjectId, p.config.account, p.config.VaultGCPOauthEngine) diff --git a/provisioner/powershell/provisioner_test.go b/provisioner/powershell/provisioner_test.go index c90d90f2e..cef4611d1 100644 --- a/provisioner/powershell/provisioner_test.go +++ b/provisioner/powershell/provisioner_test.go @@ -510,7 +510,7 @@ func TestProvisionerProvision_UploadFails(t *testing.T) { p := new(Provisioner) comm := new(packer.ScriptUploadErrorMockCommunicator) p.Prepare(config) - p.config.StartRetryTimeout = time.Second + p.config.StartRetryTimeout = 1 * time.Second err := p.Provision(context.Background(), ui, comm) if !strings.Contains(err.Error(), packer.ScriptUploadErrorMockCommunicatorError.Error()) { t.Fatalf("expected Provision() error %q to contain %q", diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index 3181c63ae..685b514ec 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -33,9 +33,7 @@ type Config struct { InlineShebang string `mapstructure:"inline_shebang"` // A duration of how long to pause after the provisioner - RawPauseAfter string `mapstructure:"pause_after"` - - PauseAfter time.Duration + PauseAfter time.Duration `mapstructure:"pause_after"` // Write the Vars to a file and source them from there rather than declaring // inline @@ -52,15 +50,14 @@ type Config struct { // The timeout for retrying to start the process. Until this timeout // is reached, if the provisioner can't start a process, it retries. // This can be set high to allow for reboots. - RawStartRetryTimeout string `mapstructure:"start_retry_timeout"` + StartRetryTimeout time.Duration `mapstructure:"start_retry_timeout"` // Whether to clean scripts up SkipClean bool `mapstructure:"skip_clean"` ExpectDisconnect bool `mapstructure:"expect_disconnect"` - startRetryTimeout time.Duration - ctx interpolate.Context + ctx interpolate.Context // name of the tmp environment variable file, if UseEnvVarFile is true envVarFile string } @@ -104,8 +101,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { p.config.InlineShebang = "/bin/sh -e" } - if p.config.RawStartRetryTimeout == "" { - p.config.RawStartRetryTimeout = "5m" + if p.config.StartRetryTimeout == 0 { + p.config.StartRetryTimeout = 5 * time.Minute } if p.config.RemoteFolder == "" { @@ -163,22 +160,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } } - if p.config.RawStartRetryTimeout != "" { - p.config.startRetryTimeout, err = time.ParseDuration(p.config.RawStartRetryTimeout) - if err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Failed parsing start_retry_timeout: %s", err)) - } - } - - if p.config.RawPauseAfter != "" { - p.config.PauseAfter, err = time.ParseDuration(p.config.RawPauseAfter) - if err != nil { - errs = packer.MultiErrorAppend( - errs, fmt.Errorf("Failed parsing pause_after: %s", err)) - } - } - if errs != nil && len(errs.Errors) > 0 { return errs } @@ -240,7 +221,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C // upload the var file var cmd *packer.RemoteCmd - err = retry.Config{StartTimeout: p.config.startRetryTimeout}.Run(ctx, func(ctx context.Context) error { + err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error { if _, err := tf.Seek(0, 0); err != nil { return err } @@ -303,7 +284,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C // and then the command is executed but the file doesn't exist // any longer. var cmd *packer.RemoteCmd - err = retry.Config{StartTimeout: p.config.startRetryTimeout}.Run(ctx, func(ctx context.Context) error { + err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error { if _, err := f.Seek(0, 0); err != nil { return err } @@ -365,7 +346,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C } } - if p.config.RawPauseAfter != "" { + if p.config.PauseAfter != 0 { ui.Say(fmt.Sprintf("Pausing %s after this provisioner...", p.config.PauseAfter)) select { case <-time.After(p.config.PauseAfter): @@ -378,7 +359,7 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C func (p *Provisioner) cleanupRemoteFile(path string, comm packer.Communicator) error { ctx := context.TODO() - err := retry.Config{StartTimeout: p.config.startRetryTimeout}.Run(ctx, func(ctx context.Context) error { + err := retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error { cmd := &packer.RemoteCmd{ Command: fmt.Sprintf("rm -f %s", path), } diff --git a/provisioner/shell/provisioner.hcl2spec.go b/provisioner/shell/provisioner.hcl2spec.go index f07abce86..9f1fbc75c 100644 --- a/provisioner/shell/provisioner.hcl2spec.go +++ b/provisioner/shell/provisioner.hcl2spec.go @@ -9,29 +9,29 @@ import ( // FlatConfig is an auto-generated flat version of Config. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatConfig struct { - PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name"` - PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type"` - PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug"` - PackerForce *bool `mapstructure:"packer_force" cty:"packer_force"` - PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error"` - PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables"` - PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables"` - Binary *bool `cty:"binary"` - ExecuteCommand *string `mapstructure:"execute_command" cty:"execute_command"` - Inline []string `cty:"inline"` - RemotePath *string `mapstructure:"remote_path" cty:"remote_path"` - Script *string `cty:"script"` - Scripts []string `cty:"scripts"` - ValidExitCodes []int `mapstructure:"valid_exit_codes" cty:"valid_exit_codes"` - Vars []string `mapstructure:"environment_vars" cty:"environment_vars"` - InlineShebang *string `mapstructure:"inline_shebang" cty:"inline_shebang"` - RawPauseAfter *string `mapstructure:"pause_after" cty:"pause_after"` - UseEnvVarFile *bool `mapstructure:"use_env_var_file" cty:"use_env_var_file"` - RemoteFolder *string `mapstructure:"remote_folder" cty:"remote_folder"` - RemoteFile *string `mapstructure:"remote_file" cty:"remote_file"` - RawStartRetryTimeout *string `mapstructure:"start_retry_timeout" cty:"start_retry_timeout"` - SkipClean *bool `mapstructure:"skip_clean" cty:"skip_clean"` - ExpectDisconnect *bool `mapstructure:"expect_disconnect" cty:"expect_disconnect"` + PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name"` + PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type"` + PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug"` + PackerForce *bool `mapstructure:"packer_force" cty:"packer_force"` + PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error"` + PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables"` + PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables"` + Binary *bool `cty:"binary"` + ExecuteCommand *string `mapstructure:"execute_command" cty:"execute_command"` + Inline []string `cty:"inline"` + RemotePath *string `mapstructure:"remote_path" cty:"remote_path"` + Script *string `cty:"script"` + Scripts []string `cty:"scripts"` + ValidExitCodes []int `mapstructure:"valid_exit_codes" cty:"valid_exit_codes"` + Vars []string `mapstructure:"environment_vars" cty:"environment_vars"` + InlineShebang *string `mapstructure:"inline_shebang" cty:"inline_shebang"` + PauseAfter *string `mapstructure:"pause_after" cty:"pause_after"` + UseEnvVarFile *bool `mapstructure:"use_env_var_file" cty:"use_env_var_file"` + RemoteFolder *string `mapstructure:"remote_folder" cty:"remote_folder"` + RemoteFile *string `mapstructure:"remote_file" cty:"remote_file"` + StartRetryTimeout *string `mapstructure:"start_retry_timeout" cty:"start_retry_timeout"` + SkipClean *bool `mapstructure:"skip_clean" cty:"skip_clean"` + ExpectDisconnect *bool `mapstructure:"expect_disconnect" cty:"expect_disconnect"` } // FlatMapstructure returns a new FlatConfig. diff --git a/provisioner/sleep/provisioner_test.go b/provisioner/sleep/provisioner_test.go index afc0d162c..6ec26c59e 100644 --- a/provisioner/sleep/provisioner_test.go +++ b/provisioner/sleep/provisioner_test.go @@ -40,8 +40,8 @@ func TestProvisioner_Provision(t *testing.T) { args args wantErr bool }{ - {"valid sleep", fields{time.Millisecond}, args{context.Background()}, false}, - {"timeout", fields{time.Millisecond}, args{ctxCancelled}, true}, + {"valid sleep", fields{1 * time.Millisecond}, args{context.Background()}, false}, + {"timeout", fields{1 * time.Millisecond}, args{ctxCancelled}, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/website/source/partials/builder/amazon/common/_RunConfig-not-required.html.md b/website/source/partials/builder/amazon/common/_RunConfig-not-required.html.md index 588f63fa5..ecb31ce6d 100644 --- a/website/source/partials/builder/amazon/common/_RunConfig-not-required.html.md +++ b/website/source/partials/builder/amazon/common/_RunConfig-not-required.html.md @@ -279,7 +279,7 @@ subnet_id to be set. If this field is left blank, Packer will try to get the VPC ID from the subnet_id. -- `windows_password_timeout` (time.Duration) - The timeout for waiting for a Windows +- `windows_password_timeout` (duration string | ex: "1h5m2s") - The timeout for waiting for a Windows password for Windows instances. Defaults to 20 minutes. Example value: 10m diff --git a/website/source/partials/builder/azure/arm/_Config-not-required.html.md b/website/source/partials/builder/azure/arm/_Config-not-required.html.md index efeb01932..b0cc4b5c8 100644 --- a/website/source/partials/builder/azure/arm/_Config-not-required.html.md +++ b/website/source/partials/builder/azure/arm/_Config-not-required.html.md @@ -34,7 +34,7 @@ "managed_image_name": "TargetImageName", "managed_image_resource_group_name": "TargetResourceGroup" -- `shared_image_gallery_timeout` (time.Duration) - How long to wait for an image to be published to the shared image +- `shared_image_gallery_timeout` (duration string | ex: "1h5m2s") - How long to wait for an image to be published to the shared image gallery before timing out. If your Packer build is failing on the Publishing to Shared Image Gallery step with the error `Original Error: context deadline exceeded`, but the image is present when you check your @@ -187,7 +187,7 @@ 3. PlanPublisher 4. PlanPromotionCode -- `polling_duration_timeout` (time.Duration) - The default PollingDuration for azure is 15mins, this property will override +- `polling_duration_timeout` (duration string | ex: "1h5m2s") - The default PollingDuration for azure is 15mins, this property will override that value. See [Azure DefaultPollingDuration](https://godoc.org/github.com/Azure/go-autorest/autorest#pkg-constants) If your Packer build is failing on the ARM deployment step with the error `Original Error: diff --git a/website/source/partials/builder/cloudstack/_Config-not-required.html.md b/website/source/partials/builder/cloudstack/_Config-not-required.html.md index 2769d20f1..bcb74665e 100644 --- a/website/source/partials/builder/cloudstack/_Config-not-required.html.md +++ b/website/source/partials/builder/cloudstack/_Config-not-required.html.md @@ -1,6 +1,6 @@ -- `async_timeout` (time.Duration) - The time duration to wait for async calls to +- `async_timeout` (duration string | ex: "1h5m2s") - The time duration to wait for async calls to finish. Defaults to 30m. - `http_get_only` (bool) - Some cloud providers only allow HTTP GET calls @@ -32,7 +32,7 @@ attached to a virtual machine. Defaults to `false`. This option is only available when using `source_iso`. -- `eject_iso_delay` (time.Duration) - Configure the duration time to wait, making sure virtual machine is able +- `eject_iso_delay` (duration string | ex: "1h5m2s") - Configure the duration time to wait, making sure virtual machine is able to finish installing OS before it ejects safely. Requires `eject_iso` set to `true` and this option is only available when using `source_iso`. diff --git a/website/source/partials/builder/digitalocean/_Config-not-required.html.md b/website/source/partials/builder/digitalocean/_Config-not-required.html.md index fe4917ba9..40e39d000 100644 --- a/website/source/partials/builder/digitalocean/_Config-not-required.html.md +++ b/website/source/partials/builder/digitalocean/_Config-not-required.html.md @@ -20,11 +20,11 @@ - `snapshot_regions` ([]string) - The regions of the resulting snapshot that will appear in your account. -- `state_timeout` (time.Duration) - The time to wait, as a duration string, for a +- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait, as a duration string, for a droplet to enter a desired state (such as "active") before timing out. The default state timeout is "6m". -- `snapshot_timeout` (time.Duration) - How long to wait for an image to be published to the shared image +- `snapshot_timeout` (duration string | ex: "1h5m2s") - How long to wait for an image to be published to the shared image gallery before timing out. If your Packer build is failing on the Publishing to Shared Image Gallery step with the error `Original Error: context deadline exceeded`, but the image is present when you check your diff --git a/website/source/partials/builder/googlecompute/_Config-not-required.html.md b/website/source/partials/builder/googlecompute/_Config-not-required.html.md index 0f137015b..a9101d361 100644 --- a/website/source/partials/builder/googlecompute/_Config-not-required.html.md +++ b/website/source/partials/builder/googlecompute/_Config-not-required.html.md @@ -88,7 +88,7 @@ - `preemptible` (bool) - If true, launch a preemptible instance. -- `state_timeout` (string) - The time to wait for instance state changes. Defaults to "5m". +- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait for instance state changes. Defaults to "5m". - `region` (string) - The region in which to launch the instance. Defaults to the region hosting the specified zone. diff --git a/website/source/partials/builder/hyperone/_Config-not-required.html.md b/website/source/partials/builder/hyperone/_Config-not-required.html.md index a392fed18..1055532c2 100644 --- a/website/source/partials/builder/hyperone/_Config-not-required.html.md +++ b/website/source/partials/builder/hyperone/_Config-not-required.html.md @@ -6,7 +6,7 @@ - `token_login` (string) - Login (an e-mail) on HyperOne platform. Set this if you want to fetch the token by SSH authentication. -- `state_timeout` (time.Duration) - Timeout for waiting on the API to complete +- `state_timeout` (duration string | ex: "1h5m2s") - Timeout for waiting on the API to complete a request. Defaults to 5m. - `image_name` (string) - The name of the resulting image. Defaults to diff --git a/website/source/partials/builder/lxc/_Config-not-required.html.md b/website/source/partials/builder/lxc/_Config-not-required.html.md index d54f4a36d..e81ce2657 100644 --- a/website/source/partials/builder/lxc/_Config-not-required.html.md +++ b/website/source/partials/builder/lxc/_Config-not-required.html.md @@ -11,7 +11,7 @@ as ssh so you can execute packer builds on a remote host. Defaults to Empty. -- `init_timeout` (string) - The timeout in seconds to wait for the the +- `init_timeout` (duration string | ex: "1h5m2s") - The timeout in seconds to wait for the the container to start. Defaults to 20 seconds. - `create_options` ([]string) - Options to pass to lxc-create. For diff --git a/website/source/partials/builder/virtualbox/common/_ShutdownConfig-not-required.html.md b/website/source/partials/builder/virtualbox/common/_ShutdownConfig-not-required.html.md index aba3347fe..93da47ced 100644 --- a/website/source/partials/builder/virtualbox/common/_ShutdownConfig-not-required.html.md +++ b/website/source/partials/builder/virtualbox/common/_ShutdownConfig-not-required.html.md @@ -8,12 +8,12 @@ since reboots may fail and specify the final shutdown command in your last script. -- `shutdown_timeout` (string) - The amount of time to wait after executing the +- `shutdown_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait after executing the shutdown_command for the virtual machine to actually shut down. If it doesn't shut down in this time, it is an error. By default, the timeout is 5m or five minutes. -- `post_shutdown_delay` (string) - The amount of time to wait after shutting +- `post_shutdown_delay` (duration string | ex: "1h5m2s") - The amount of time to wait after shutting down the virtual machine. If you get the error Error removing floppy controller, you might need to set this to 5m or so. By default, the delay is 0s or disabled. diff --git a/website/source/partials/builder/yandex/_Config-not-required.html.md b/website/source/partials/builder/yandex/_Config-not-required.html.md index 18c4e4ff6..8a0674934 100644 --- a/website/source/partials/builder/yandex/_Config-not-required.html.md +++ b/website/source/partials/builder/yandex/_Config-not-required.html.md @@ -73,6 +73,6 @@ - `zone` (string) - The name of the zone to launch the instance. This defaults to `ru-central1-a`. -- `state_timeout` (time.Duration) - The time to wait for instance state changes. +- `state_timeout` (duration string | ex: "1h5m2s") - The time to wait for instance state changes. Defaults to `5m`. \ No newline at end of file diff --git a/website/source/partials/common/bootcommand/_BootConfig-not-required.html.md b/website/source/partials/common/bootcommand/_BootConfig-not-required.html.md index 69791b48a..3159ff57d 100644 --- a/website/source/partials/common/bootcommand/_BootConfig-not-required.html.md +++ b/website/source/partials/common/bootcommand/_BootConfig-not-required.html.md @@ -1,12 +1,12 @@ -- `boot_keygroup_interval` (string) - Time to wait after sending a group of key pressses. The value of this +- `boot_keygroup_interval` (duration string | ex: "1h5m2s") - Time to wait after sending a group of key pressses. The value of this should be a duration. Examples are `5s` and `1m30s` which will cause Packer to wait five seconds and one minute 30 seconds, respectively. If this isn't specified, a sensible default value is picked depending on the builder type. -- `boot_wait` (string) - The time to wait after booting the initial virtual machine before typing +- `boot_wait` (duration string | ex: "1h5m2s") - The time to wait after booting the initial virtual machine before typing the `boot_command`. The value of this should be a duration. Examples are `5s` and `1m30s` which will cause Packer to wait five seconds and one minute 30 seconds, respectively. If this isn't specified, the default is diff --git a/website/source/partials/common/bootcommand/_VNCConfig-not-required.html.md b/website/source/partials/common/bootcommand/_VNCConfig-not-required.html.md index d7081e407..27cba7b91 100644 --- a/website/source/partials/common/bootcommand/_VNCConfig-not-required.html.md +++ b/website/source/partials/common/bootcommand/_VNCConfig-not-required.html.md @@ -3,5 +3,5 @@ - `disable_vnc` (bool) - Whether to create a VNC connection or not. A boot_command cannot be used when this is true. Defaults to false. -- `boot_key_interval` (string) - Time in ms to wait between each key press +- `boot_key_interval` (duration string | ex: "1h5m2s") - Time in ms to wait between each key press \ No newline at end of file diff --git a/website/source/partials/common/shutdowncommand/_ShutdownConfig-not-required.html.md b/website/source/partials/common/shutdowncommand/_ShutdownConfig-not-required.html.md index 6094b9154..6d65b9e46 100644 --- a/website/source/partials/common/shutdowncommand/_ShutdownConfig-not-required.html.md +++ b/website/source/partials/common/shutdowncommand/_ShutdownConfig-not-required.html.md @@ -9,7 +9,7 @@ reboots may fail) and instead specify the final shutdown command in your last script. -- `shutdown_timeout` (string) - The amount of time to wait after executing the shutdown_command for the +- `shutdown_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait after executing the shutdown_command for the virtual machine to actually shut down. If the machine doesn't shut down in this time it is considered an error. By default, the time out is "5m" (five minutes). diff --git a/website/source/partials/helper/communicator/_Config-not-required.html.md b/website/source/partials/helper/communicator/_Config-not-required.html.md index e994c8fe1..15df6051a 100644 --- a/website/source/partials/helper/communicator/_Config-not-required.html.md +++ b/website/source/partials/helper/communicator/_Config-not-required.html.md @@ -15,7 +15,7 @@ that uses `docker exec` and `docker cp` to execute scripts and copy files. -- `pause_before_connecting` (time.Duration) - We recommend that you enable SSH or WinRM as the very last step in your +- `pause_before_connecting` (duration string | ex: "1h5m2s") - We recommend that you enable SSH or WinRM as the very last step in your guest's bootstrap script, but sometimes you may have a race condition where you need Packer to wait before attempting to connect to your guest. diff --git a/website/source/partials/helper/communicator/_SSH-not-required.html.md b/website/source/partials/helper/communicator/_SSH-not-required.html.md index 9aff6f74e..2adefaca6 100644 --- a/website/source/partials/helper/communicator/_SSH-not-required.html.md +++ b/website/source/partials/helper/communicator/_SSH-not-required.html.md @@ -36,7 +36,7 @@ - `ssh_pty` (bool) - If `true`, a PTY will be requested for the SSH connection. This defaults to `false`. -- `ssh_timeout` (time.Duration) - The time to wait for SSH to become available. Packer uses this to +- `ssh_timeout` (duration string | ex: "1h5m2s") - The time to wait for SSH to become available. Packer uses this to determine when the machine has booted so this is usually quite long. Example value: `10m`. @@ -79,10 +79,10 @@ - `ssh_proxy_password` (string) - The optional password to use to authenticate with the proxy server. -- `ssh_keep_alive_interval` (time.Duration) - How often to send "keep alive" messages to the server. Set to a negative +- `ssh_keep_alive_interval` (duration string | ex: "1h5m2s") - How often to send "keep alive" messages to the server. Set to a negative value (`-1s`) to disable. Example value: `10s`. Defaults to `5s`. -- `ssh_read_write_timeout` (time.Duration) - The amount of time to wait for a remote command to end. This might be +- `ssh_read_write_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait for a remote command to end. This might be useful if, for example, packer hangs on a connection after a reboot. Example: `5m`. Disabled by default. diff --git a/website/source/partials/helper/communicator/_WinRM-not-required.html.md b/website/source/partials/helper/communicator/_WinRM-not-required.html.md index aac408a0b..d77c4d9df 100644 --- a/website/source/partials/helper/communicator/_WinRM-not-required.html.md +++ b/website/source/partials/helper/communicator/_WinRM-not-required.html.md @@ -14,7 +14,7 @@ unencrypted connection and `5986` for SSL when `winrm_use_ssl` is set to true. -- `winrm_timeout` (time.Duration) - The amount of time to wait for WinRM to become available. This defaults +- `winrm_timeout` (duration string | ex: "1h5m2s") - The amount of time to wait for WinRM to become available. This defaults to `30m` since setting up a Windows machine generally takes a long time. - `winrm_use_ssl` (bool) - If `true`, use HTTPS for WinRM.