From 7732f7998c89c2921708ad0bbed1644ebdbfb088 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 23 Mar 2021 12:31:13 +0100 Subject: [PATCH] Add http_content func to serve variables from HTTP @ preseed (#10801) This imports hashicorp/packer-plugin-sdk#43 * code generate things * update docs * update guides * update examples We want to add a new guide. --- builder/cloudstack/builder.go | 7 +- builder/cloudstack/config.hcl2spec.go | 2 + builder/hyperv/iso/builder.go | 7 +- builder/hyperv/iso/builder.hcl2spec.go | 2 + builder/hyperv/vmcx/builder.go | 7 +- builder/hyperv/vmcx/builder.hcl2spec.go | 2 + builder/parallels/iso/builder.go | 7 +- builder/parallels/iso/builder.hcl2spec.go | 2 + builder/proxmox/clone/config.hcl2spec.go | 2 + builder/proxmox/common/builder.go | 7 +- builder/proxmox/common/config.hcl2spec.go | 2 + builder/proxmox/iso/config.hcl2spec.go | 2 + builder/qemu/builder.go | 7 +- builder/qemu/config.hcl2spec.go | 2 + builder/qemu/step_run.go | 2 + builder/vagrant/builder.hcl2spec.go | 2 + builder/virtualbox/iso/builder.go | 7 +- builder/virtualbox/iso/builder.hcl2spec.go | 2 + builder/virtualbox/ovf/builder.go | 7 +- builder/virtualbox/ovf/config.hcl2spec.go | 2 + builder/virtualbox/vm/builder.go | 7 +- builder/virtualbox/vm/config.hcl2spec.go | 2 + builder/vmware/iso/builder.go | 7 +- builder/vmware/iso/config.hcl2spec.go | 2 + builder/vmware/vmx/builder.go | 7 +- builder/vmware/vmx/config.hcl2spec.go | 2 + builder/vsphere/clone/builder.go | 7 +- builder/vsphere/clone/config.hcl2spec.go | 2 + builder/vsphere/iso/builder.go | 7 +- builder/vsphere/iso/config.hcl2spec.go | 2 + command/hcl2_upgrade.go | 1 + .../hcl/linux/source.parallels-iso.pkr.hcl | 2 +- .../hcl/linux/source.virtualbox-iso.pkr.hcl | 2 +- examples/hcl/linux/variables.18.04.pkr.hcl | 4 +- examples/hcl/linux/variables.common.pkr.hcl | 6 ++ go.mod | 2 +- go.sum | 4 +- .../didyoumean/name_suggestion.go | 24 ++++++ .../multistep/commonsteps/http_config.go | 14 ++++ .../multistep/commonsteps/step_http_server.go | 81 +++++++++++++++++-- .../packer-plugin-sdk/template/funcs.go | 5 +- .../packer-plugin-sdk/version/version.go | 4 +- vendor/modules.txt | 3 +- website/content/docs/builders/cloudstack.mdx | 15 ---- .../content/docs/builders/parallels/iso.mdx | 22 ++--- website/content/docs/provisioners/file.mdx | 15 ++-- .../preseed_ubuntu.mdx | 8 +- .../partials/builders/boot-command.mdx | 4 +- .../commonsteps/HTTPConfig-not-required.mdx | 9 +++ 49 files changed, 212 insertions(+), 138 deletions(-) create mode 100644 vendor/github.com/hashicorp/packer-plugin-sdk/didyoumean/name_suggestion.go diff --git a/builder/cloudstack/builder.go b/builder/cloudstack/builder.go index 53d71a901..08f9ebeda 100644 --- a/builder/cloudstack/builder.go +++ b/builder/cloudstack/builder.go @@ -60,12 +60,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) // Build the steps. steps := []multistep.Step{ &stepPrepareConfig{}, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &stepKeypair{ Debug: b.config.PackerDebug, Comm: &b.config.Comm, diff --git a/builder/cloudstack/config.hcl2spec.go b/builder/cloudstack/config.hcl2spec.go index 171a7dffa..638223c4c 100644 --- a/builder/cloudstack/config.hcl2spec.go +++ b/builder/cloudstack/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -135,6 +136,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/hyperv/iso/builder.go b/builder/hyperv/iso/builder.go index d99de8c15..c87e89271 100644 --- a/builder/hyperv/iso/builder.go +++ b/builder/hyperv/iso/builder.go @@ -211,12 +211,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) Directories: b.config.FloppyConfig.FloppyDirectories, Label: b.config.FloppyConfig.FloppyLabel, }, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &hypervcommon.StepCreateSwitch{ SwitchName: b.config.SwitchName, }, diff --git a/builder/hyperv/iso/builder.hcl2spec.go b/builder/hyperv/iso/builder.hcl2spec.go index afc83c364..b2b74f892 100644 --- a/builder/hyperv/iso/builder.hcl2spec.go +++ b/builder/hyperv/iso/builder.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -141,6 +142,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index 319bff68b..b2c06b4ee 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -251,12 +251,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) Directories: b.config.FloppyConfig.FloppyDirectories, Label: b.config.FloppyConfig.FloppyLabel, }, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &hypervcommon.StepCreateSwitch{ SwitchName: b.config.SwitchName, }, diff --git a/builder/hyperv/vmcx/builder.hcl2spec.go b/builder/hyperv/vmcx/builder.hcl2spec.go index 2b827e8c2..b24a8c663 100644 --- a/builder/hyperv/vmcx/builder.hcl2spec.go +++ b/builder/hyperv/vmcx/builder.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -143,6 +144,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/parallels/iso/builder.go b/builder/parallels/iso/builder.go index 356ccec76..a5d99b272 100644 --- a/builder/parallels/iso/builder.go +++ b/builder/parallels/iso/builder.go @@ -209,12 +209,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) Directories: b.config.FloppyConfig.FloppyDirectories, Label: b.config.FloppyConfig.FloppyLabel, }, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), new(stepCreateVM), new(stepCreateDisk), new(stepSetBootOrder), diff --git a/builder/parallels/iso/builder.hcl2spec.go b/builder/parallels/iso/builder.hcl2spec.go index 9ab62b8c3..b4d20dc72 100644 --- a/builder/parallels/iso/builder.hcl2spec.go +++ b/builder/parallels/iso/builder.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -126,6 +127,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/proxmox/clone/config.hcl2spec.go b/builder/proxmox/clone/config.hcl2spec.go index 32b6e64f3..5ea7b18c2 100644 --- a/builder/proxmox/clone/config.hcl2spec.go +++ b/builder/proxmox/clone/config.hcl2spec.go @@ -20,6 +20,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -130,6 +131,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/proxmox/common/builder.go b/builder/proxmox/common/builder.go index 0d4391afd..9a9e9585b 100644 --- a/builder/proxmox/common/builder.go +++ b/builder/proxmox/common/builder.go @@ -52,12 +52,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook, &stepStartVM{ vmCreator: b.vmCreator, }, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &stepTypeBootCommand{ BootConfig: b.config.BootConfig, Ctx: b.config.Ctx, diff --git a/builder/proxmox/common/config.hcl2spec.go b/builder/proxmox/common/config.hcl2spec.go index f6d11221c..95ba40895 100644 --- a/builder/proxmox/common/config.hcl2spec.go +++ b/builder/proxmox/common/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -127,6 +128,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/proxmox/iso/config.hcl2spec.go b/builder/proxmox/iso/config.hcl2spec.go index 88aa679bb..24650d35e 100644 --- a/builder/proxmox/iso/config.hcl2spec.go +++ b/builder/proxmox/iso/config.hcl2spec.go @@ -20,6 +20,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -136,6 +137,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 5bbc5268d..c9e63a312 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -96,12 +96,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) QemuImgArgs: b.config.QemuImgArgs, }, new(stepHTTPIPDiscover), - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &stepPortForward{ CommunicatorType: b.config.CommConfig.Comm.Type, NetBridge: b.config.NetBridge, diff --git a/builder/qemu/config.hcl2spec.go b/builder/qemu/config.hcl2spec.go index dc141cd7d..dc331e20c 100644 --- a/builder/qemu/config.hcl2spec.go +++ b/builder/qemu/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -153,6 +154,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/qemu/step_run.go b/builder/qemu/step_run.go index be802348b..37239396f 100644 --- a/builder/qemu/step_run.go +++ b/builder/qemu/step_run.go @@ -298,6 +298,7 @@ func (s *stepRun) applyUserOverrides(defaultArgs map[string]interface{}, config HTTPIP string HTTPPort int HTTPDir string + HTTPContent map[string]string OutputDir string Name string SSHHostPort int @@ -308,6 +309,7 @@ func (s *stepRun) applyUserOverrides(defaultArgs map[string]interface{}, config HTTPIP: httpIp, HTTPPort: httpPort, HTTPDir: config.HTTPDir, + HTTPContent: config.HTTPContent, OutputDir: config.OutputDir, Name: config.VMName, SSHHostPort: commHostPort, diff --git a/builder/vagrant/builder.hcl2spec.go b/builder/vagrant/builder.hcl2spec.go index e815fa016..09f5d7660 100644 --- a/builder/vagrant/builder.hcl2spec.go +++ b/builder/vagrant/builder.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -128,6 +129,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 4421a122c..f8adc5801 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -406,12 +406,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) Label: b.config.CDConfig.CDLabel, }, new(vboxcommon.StepHTTPIPDiscover), - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &vboxcommon.StepSshKeyPair{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName), diff --git a/builder/virtualbox/iso/builder.hcl2spec.go b/builder/virtualbox/iso/builder.hcl2spec.go index ca02f022e..c44c81ca8 100644 --- a/builder/virtualbox/iso/builder.hcl2spec.go +++ b/builder/virtualbox/iso/builder.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -162,6 +163,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/virtualbox/ovf/builder.go b/builder/virtualbox/ovf/builder.go index fb0a53965..7dd1de56c 100644 --- a/builder/virtualbox/ovf/builder.go +++ b/builder/virtualbox/ovf/builder.go @@ -65,12 +65,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) Label: b.config.CDConfig.CDLabel, }, new(vboxcommon.StepHTTPIPDiscover), - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &vboxcommon.StepSshKeyPair{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName), diff --git a/builder/virtualbox/ovf/config.hcl2spec.go b/builder/virtualbox/ovf/config.hcl2spec.go index 845b27f24..1129ae208 100644 --- a/builder/virtualbox/ovf/config.hcl2spec.go +++ b/builder/virtualbox/ovf/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -138,6 +139,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/virtualbox/vm/builder.go b/builder/virtualbox/vm/builder.go index b762e65f7..04be971a3 100644 --- a/builder/virtualbox/vm/builder.go +++ b/builder/virtualbox/vm/builder.go @@ -64,12 +64,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) KeepRegistered: b.config.KeepRegistered, }, new(vboxcommon.StepHTTPIPDiscover), - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &vboxcommon.StepDownloadGuestAdditions{ GuestAdditionsMode: b.config.GuestAdditionsMode, GuestAdditionsURL: b.config.GuestAdditionsURL, diff --git a/builder/virtualbox/vm/config.hcl2spec.go b/builder/virtualbox/vm/config.hcl2spec.go index e672cd48b..9ac76a4f4 100644 --- a/builder/virtualbox/vm/config.hcl2spec.go +++ b/builder/virtualbox/vm/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -136,6 +137,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 9ef6f6569..7b712356c 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -117,12 +117,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) }, &vmwcommon.StepSuppressMessages{}, &vmwcommon.StepHTTPIPDiscover{}, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &vmwcommon.StepConfigureVNC{ Enabled: !b.config.DisableVNC && !b.config.VNCOverWebsocket, VNCBindAddress: b.config.VNCBindAddress, diff --git a/builder/vmware/iso/config.hcl2spec.go b/builder/vmware/iso/config.hcl2spec.go index 724157428..9ee645c8a 100644 --- a/builder/vmware/iso/config.hcl2spec.go +++ b/builder/vmware/iso/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -167,6 +168,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/vmware/vmx/builder.go b/builder/vmware/vmx/builder.go index dbf8b1b58..b8ec91906 100644 --- a/builder/vmware/vmx/builder.go +++ b/builder/vmware/vmx/builder.go @@ -108,12 +108,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) }, &vmwcommon.StepSuppressMessages{}, &vmwcommon.StepHTTPIPDiscover{}, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &vmwcommon.StepUploadVMX{ RemoteType: b.config.RemoteType, }, diff --git a/builder/vmware/vmx/config.hcl2spec.go b/builder/vmware/vmx/config.hcl2spec.go index 0af743f1a..f18765929 100644 --- a/builder/vmware/vmx/config.hcl2spec.go +++ b/builder/vmware/vmx/config.hcl2spec.go @@ -19,6 +19,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -149,6 +150,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/vsphere/clone/builder.go b/builder/vsphere/clone/builder.go index 169f6b5f5..d9c34bab9 100644 --- a/builder/vsphere/clone/builder.go +++ b/builder/vsphere/clone/builder.go @@ -89,12 +89,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) HTTPIP: b.config.BootConfig.HTTPIP, Network: b.config.WaitIpConfig.GetIPNet(), }, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &common.StepSshKeyPair{ Debug: b.config.PackerDebug, DebugKeyPath: fmt.Sprintf("%s.pem", b.config.PackerBuildName), diff --git a/builder/vsphere/clone/config.hcl2spec.go b/builder/vsphere/clone/config.hcl2spec.go index 790eeb7ae..ad7787e7e 100644 --- a/builder/vsphere/clone/config.hcl2spec.go +++ b/builder/vsphere/clone/config.hcl2spec.go @@ -20,6 +20,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -159,6 +160,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/builder/vsphere/iso/builder.go b/builder/vsphere/iso/builder.go index 567046fa2..f975bad84 100644 --- a/builder/vsphere/iso/builder.go +++ b/builder/vsphere/iso/builder.go @@ -92,12 +92,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) HTTPIP: b.config.BootConfig.HTTPIP, Network: b.config.WaitIpConfig.GetIPNet(), }, - &commonsteps.StepHTTPServer{ - HTTPDir: b.config.HTTPDir, - HTTPPortMin: b.config.HTTPPortMin, - HTTPPortMax: b.config.HTTPPortMax, - HTTPAddress: b.config.HTTPAddress, - }, + commonsteps.HTTPServerFromHTTPConfig(&b.config.HTTPConfig), &common.StepRun{ Config: &b.config.RunConfig, SetOrder: true, diff --git a/builder/vsphere/iso/config.hcl2spec.go b/builder/vsphere/iso/config.hcl2spec.go index dea92fa94..ee8298e49 100644 --- a/builder/vsphere/iso/config.hcl2spec.go +++ b/builder/vsphere/iso/config.hcl2spec.go @@ -20,6 +20,7 @@ type FlatConfig struct { PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables" hcl:"packer_user_variables"` PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables" hcl:"packer_sensitive_variables"` HTTPDir *string `mapstructure:"http_directory" cty:"http_directory" hcl:"http_directory"` + HTTPContent map[string]string `mapstructure:"http_content" cty:"http_content" hcl:"http_content"` HTTPPortMin *int `mapstructure:"http_port_min" cty:"http_port_min" hcl:"http_port_min"` HTTPPortMax *int `mapstructure:"http_port_max" cty:"http_port_max" hcl:"http_port_max"` HTTPAddress *string `mapstructure:"http_bind_address" cty:"http_bind_address" hcl:"http_bind_address"` @@ -161,6 +162,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, "http_directory": &hcldec.AttrSpec{Name: "http_directory", Type: cty.String, Required: false}, + "http_content": &hcldec.AttrSpec{Name: "http_content", Type: cty.Map(cty.String), Required: false}, "http_port_min": &hcldec.AttrSpec{Name: "http_port_min", Type: cty.Number, Required: false}, "http_port_max": &hcldec.AttrSpec{Name: "http_port_max", Type: cty.Number, Required: false}, "http_bind_address": &hcldec.AttrSpec{Name: "http_bind_address", Type: cty.String, Required: false}, diff --git a/command/hcl2_upgrade.go b/command/hcl2_upgrade.go index 5273e3996..cd70b62ba 100644 --- a/command/hcl2_upgrade.go +++ b/command/hcl2_upgrade.go @@ -1216,6 +1216,7 @@ var PASSTHROUGHS = map[string]string{"NVME_Present": "{{ .NVME_Present }}", "WinRMPassword": "{{ .WinRMPassword }}", "DefaultOrganizationID": "{{ .DefaultOrganizationID }}", "HTTPDir": "{{ .HTTPDir }}", + "HTTPContent": "{{ .HTTPContent }}", "SegmentPath": "{{ .SegmentPath }}", "NewVHDSizeBytes": "{{ .NewVHDSizeBytes }}", "CTyp": "{{ .CTyp }}", diff --git a/examples/hcl/linux/source.parallels-iso.pkr.hcl b/examples/hcl/linux/source.parallels-iso.pkr.hcl index e95b467d0..7f2c1a71a 100644 --- a/examples/hcl/linux/source.parallels-iso.pkr.hcl +++ b/examples/hcl/linux/source.parallels-iso.pkr.hcl @@ -2,7 +2,7 @@ source "parallels-iso" "base-ubuntu-amd64" { boot_wait = "10s" guest_os_type = "ubuntu" - http_directory = local.http_directory + http_content = local.http_directory_content parallels_tools_flavor = "lin" prlctl_version_file = ".prlctl_version" shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now" diff --git a/examples/hcl/linux/source.virtualbox-iso.pkr.hcl b/examples/hcl/linux/source.virtualbox-iso.pkr.hcl index 0d8011e4c..5cd5f1a89 100644 --- a/examples/hcl/linux/source.virtualbox-iso.pkr.hcl +++ b/examples/hcl/linux/source.virtualbox-iso.pkr.hcl @@ -1,7 +1,7 @@ source "virtualbox-iso" "base-ubuntu-amd64" { headless = var.headless guest_os_type = "Ubuntu_64" - http_directory = local.http_directory + http_content = local.http_directory_content shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now" ssh_username = "vagrant" ssh_password = "vagrant" diff --git a/examples/hcl/linux/variables.18.04.pkr.hcl b/examples/hcl/linux/variables.18.04.pkr.hcl index 76c9d48c0..abdbc8ea4 100644 --- a/examples/hcl/linux/variables.18.04.pkr.hcl +++ b/examples/hcl/linux/variables.18.04.pkr.hcl @@ -1,9 +1,9 @@ variable "ubuntu_1804_version" { - default = "18.04.4" + default = "18.04.5" } locals { - iso_url_ubuntu_1804 = "http://cdimage.ubuntu.com/ubuntu/releases/18.04/release/ubuntu-18.04.4-server-amd64.iso" + iso_url_ubuntu_1804 = "http://cdimage.ubuntu.com/ubuntu/releases/18.04/release/ubuntu-${var.ubuntu_1804_version}-server-amd64.iso" iso_checksum_url_ubuntu_1804 = "http://cdimage.ubuntu.com/ubuntu/releases/18.04/release/SHA256SUMS" ubuntu_1804_boot_command = [ "", diff --git a/examples/hcl/linux/variables.common.pkr.hcl b/examples/hcl/linux/variables.common.pkr.hcl index 19231c04d..01a178945 100644 --- a/examples/hcl/linux/variables.common.pkr.hcl +++ b/examples/hcl/linux/variables.common.pkr.hcl @@ -20,4 +20,10 @@ locals { // value. This validates that the http directory exists even before starting // any builder/provisioner. http_directory = dirname(convert(fileset(".", "etc/http/*"), list(string))[0]) + http_directory_content = { + "/alpine-answers" = file("${local.http_directory}/alpine-answers"), + "/alpine-setup.sh" = file("${local.http_directory}/alpine-setup.sh"), + "/preseed_hardcoded_ip.cfg" = file("${local.http_directory}/preseed_hardcoded_ip.cfg"), + "/preseed.cfg" = file("${local.http_directory}/preseed.cfg"), + } } diff --git a/go.mod b/go.mod index e8950e8bc..415c54661 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/hashicorp/go-version v1.2.0 github.com/hashicorp/hcl/v2 v2.8.0 github.com/hashicorp/packer-plugin-docker v0.0.2 - github.com/hashicorp/packer-plugin-sdk v0.0.14 + github.com/hashicorp/packer-plugin-sdk v0.1.1-0.20210323111710-5a7ab7f7a1c0 github.com/hashicorp/vault/api v1.0.4 github.com/hetznercloud/hcloud-go v1.15.1 github.com/hyperonecom/h1-client-go v0.0.0-20191203060043-b46280e4c4a4 diff --git a/go.sum b/go.sum index d67880e44..6452de5bd 100644 --- a/go.sum +++ b/go.sum @@ -394,6 +394,7 @@ github.com/hashicorp/packer v1.6.7-0.20210125170305-539638b0f951/go.mod h1:Z3eun github.com/hashicorp/packer v1.6.7-0.20210126105722-aef4ced967ec/go.mod h1:2+Vo/c/fA+TD9yFc/h9jQMFm4yG+IymQIr0OdJJOPiE= github.com/hashicorp/packer v1.6.7-0.20210208125835-f616955ebcb6/go.mod h1:7f5ZpTTRG53rQ58BcTADuTnpiBcB3wapuxl4sF2sGMM= github.com/hashicorp/packer v1.6.7-0.20210217093213-201869d627bf/go.mod h1:+EWPPcqee4h8S/y913Dnta1eJkgiqsGXBQgB75A2qV0= +github.com/hashicorp/packer v1.7.0/go.mod h1:3KRJcwOctl2JaAGpQMI1bWQRArfWNWqcYjO6AOsVVGQ= github.com/hashicorp/packer-plugin-docker v0.0.2 h1:j/hQTogaN2pZfZohlZTRu5YvNZg2/qtYYHkxPBxv2Oo= github.com/hashicorp/packer-plugin-docker v0.0.2/go.mod h1:A2p9qztS4n88KsNF+qBM7BWw2HndW636GpFIjNSvbKM= github.com/hashicorp/packer-plugin-sdk v0.0.6/go.mod h1:Nvh28f+Jmpp2rcaN79bULTouNkGNDRfHckhHKTAXtyU= @@ -403,8 +404,9 @@ github.com/hashicorp/packer-plugin-sdk v0.0.7-0.20210122130548-45a6ca0a9365/go.m github.com/hashicorp/packer-plugin-sdk v0.0.10-0.20210126105622-8e1648006d93/go.mod h1:AtWQLNfpn7cgH2SmZ1PTedwqNOhiPvzcuKfH5sDvIQ0= github.com/hashicorp/packer-plugin-sdk v0.0.11/go.mod h1:GNb0WNs7zibb8vzUZce1As64z2AW0FEMwhe2J7/NW5I= github.com/hashicorp/packer-plugin-sdk v0.0.12/go.mod h1:hs82OYeufirGG6KRENMpjBWomnIlte99X6wXAPThJ5I= -github.com/hashicorp/packer-plugin-sdk v0.0.14 h1:42WOZLmIbAYYC1WXxtlrQZN+fFdysVvTmj3jtoI6gOU= github.com/hashicorp/packer-plugin-sdk v0.0.14/go.mod h1:tNb3XzJPnjMl3QuUdKmF47B5ImerdTakalHzUAvW0aw= +github.com/hashicorp/packer-plugin-sdk v0.1.1-0.20210323111710-5a7ab7f7a1c0 h1:nw4RqF7C4jUWGo5PGDG4dSclU+G/vXyVBHIu5j7akd4= +github.com/hashicorp/packer-plugin-sdk v0.1.1-0.20210323111710-5a7ab7f7a1c0/go.mod h1:1d3nqB9LUsXMQaNUiL67Q+WYEtjsVcLNTX8ikVlpBrc= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/serf v0.9.2 h1:yJoyfZXo4Pk2p/M/viW+YLibBFiIbKoP79gu7kDAFP0= github.com/hashicorp/serf v0.9.2/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/didyoumean/name_suggestion.go b/vendor/github.com/hashicorp/packer-plugin-sdk/didyoumean/name_suggestion.go new file mode 100644 index 000000000..333811fc4 --- /dev/null +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/didyoumean/name_suggestion.go @@ -0,0 +1,24 @@ +package didyoumean + +import ( + "github.com/agext/levenshtein" +) + +// NameSuggestion tries to find a name from the given slice of suggested names +// that is close to the given name and returns it if found. If no suggestion is +// close enough, returns the empty string. +// +// The suggestions are tried in order, so earlier suggestions take precedence if +// the given string is similar to two or more suggestions. +// +// This function is intended to be used with a relatively-small number of +// suggestions. It's not optimized for hundreds or thousands of them. +func NameSuggestion(given string, suggestions []string) string { + for _, suggestion := range suggestions { + dist := levenshtein.Distance(given, suggestion, nil) + if dist < 3 { // threshold determined experimentally + return suggestion + } + } + return "" +} diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/http_config.go b/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/http_config.go index 8a85accfd..cf20965d0 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/http_config.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/http_config.go @@ -23,6 +23,15 @@ type HTTPConfig struct { // started. The address and port of the HTTP server will be available as // variables in `boot_command`. This is covered in more detail below. HTTPDir string `mapstructure:"http_directory"` + // Key/Values to serve using an HTTP server. http_content works like and + // conflicts with http_directory The keys represent the paths and the values + // contents. This is useful for hosting kickstart files and so on. By + // default this is empty, which means no HTTP server will be started. The + // address and port of the HTTP server will be available as variables in + // `boot_command`. This is covered in more detail below. Example: Setting + // `"foo/bar"="baz"`, will allow you to http get on + // `http://{http_ip}:{http_port}/foo/bar`. + HTTPContent map[string]string `mapstructure:"http_content"` // These are the minimum and maximum port to use for the HTTP server // started to serve the `http_directory`. Because Packer often runs in // parallel, Packer will choose a randomly available port in this range to @@ -66,5 +75,10 @@ func (c *HTTPConfig) Prepare(ctx *interpolate.Context) []error { errors.New("http_port_min must be less than http_port_max")) } + if len(c.HTTPContent) > 0 && len(c.HTTPDir) > 0 { + errs = append(errs, + errors.New("http_content cannot be used in conjunction with http_dir. Consider using the file function to load file in memory and serve them with http_content: https://www.packer.io/docs/templates/hcl_templates/functions/file/file")) + } + return errs } diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/step_http_server.go b/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/step_http_server.go index 42a3f5d4f..3b4f7dc5b 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/step_http_server.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps/step_http_server.go @@ -3,14 +3,28 @@ package commonsteps import ( "context" "fmt" - + "log" "net/http" + "os" + "path" + "sort" + "github.com/hashicorp/packer-plugin-sdk/didyoumean" "github.com/hashicorp/packer-plugin-sdk/multistep" "github.com/hashicorp/packer-plugin-sdk/net" packersdk "github.com/hashicorp/packer-plugin-sdk/packer" ) +func HTTPServerFromHTTPConfig(cfg *HTTPConfig) *StepHTTPServer { + return &StepHTTPServer{ + HTTPDir: cfg.HTTPDir, + HTTPContent: cfg.HTTPContent, + HTTPPortMin: cfg.HTTPPortMin, + HTTPPortMax: cfg.HTTPPortMax, + HTTPAddress: cfg.HTTPAddress, + } +} + // This step creates and runs the HTTP server that is serving files from the // directory specified by the 'http_directory` configuration parameter in the // template. @@ -22,6 +36,7 @@ import ( // http_port int - The port the HTTP server started on. type StepHTTPServer struct { HTTPDir string + HTTPContent map[string]string HTTPPortMin int HTTPPortMax int HTTPAddress string @@ -29,16 +44,58 @@ type StepHTTPServer struct { l *net.Listener } +func (s *StepHTTPServer) Handler() http.Handler { + if s.HTTPDir != "" { + return http.FileServer(http.Dir(s.HTTPDir)) + } + + return MapServer(s.HTTPContent) +} + +type MapServer map[string]string + +func (s MapServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { + path := path.Clean(r.URL.Path) + content, found := s[path] + if !found { + paths := make([]string, 0, len(s)) + for k := range s { + paths = append(paths, k) + } + sort.Strings(paths) + err := fmt.Sprintf("%s not found.", path) + if sug := didyoumean.NameSuggestion(path, paths); sug != "" { + err += fmt.Sprintf(" Did you mean %q?", sug) + } + + http.Error(w, err, http.StatusNotFound) + return + } + + if _, err := w.Write([]byte(content)); err != nil { + // log err in case the file couldn't be 100% transferred for example. + log.Printf("http_content serve error: %v", err) + } +} + func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packersdk.Ui) - if s.HTTPDir == "" { + if s.HTTPDir == "" && len(s.HTTPContent) == 0 { state.Put("http_port", 0) return multistep.ActionContinue } + if s.HTTPDir != "" { + if _, err := os.Stat(s.HTTPDir); err != nil { + err := fmt.Errorf("Error finding %q: %s", s.HTTPDir, err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + // Find an available TCP port for our HTTP server - var httpAddr string var err error s.l, err = net.ListenRangeConfig{ Min: s.HTTPPortMin, @@ -57,8 +114,7 @@ func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) mult ui.Say(fmt.Sprintf("Starting HTTP server on port %d", s.l.Port)) // Start the HTTP server and run it in the background - fileServer := http.FileServer(http.Dir(s.HTTPDir)) - server := &http.Server{Addr: httpAddr, Handler: fileServer} + server := &http.Server{Addr: "", Handler: s.Handler()} go server.Serve(s.l) // Save the address into the state so it can be accessed in the future @@ -67,9 +123,20 @@ func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) mult return multistep.ActionContinue } -func (s *StepHTTPServer) Cleanup(multistep.StateBag) { +func (s *StepHTTPServer) Cleanup(state multistep.StateBag) { if s.l != nil { + ui := state.Get("ui").(packersdk.Ui) + // Close the listener so that the HTTP server stops - s.l.Close() + if err := s.l.Close(); err != nil { + err = fmt.Errorf("Failed closing http server on port %d: %w", s.l.Port, err) + ui.Error(err.Error()) + // Here this error should be shown to the UI but it won't + // specifically stop Packer from terminating successfully. It could + // cause a "Listen leak" if it happenned a lot. Though Listen will + // try other ports if one is already used. In the case we want to + // Listen on only one port, the next Listen call could fail or be + // longer than expected. + } } } diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/template/funcs.go b/vendor/github.com/hashicorp/packer-plugin-sdk/template/funcs.go index 6a340d1c2..cf1e691dd 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/template/funcs.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/template/funcs.go @@ -56,7 +56,10 @@ func Vault(path string, key string) (string, error) { } // neither v1 nor v2 proudced a valid value - return "", fmt.Errorf("Vault data was empty at the given path. Warnings: %s", strings.Join(secret.Warnings, "; ")) + return "", fmt.Errorf("Vault data was empty at the given path. Check "+ + "the Vault function docs for help: "+ + "https://www.packer.io/docs/templates/hcl_templates/functions/contextual/vault. "+ + "Original warnings from Vault call: %s", strings.Join(secret.Warnings, "; ")) } if val, ok := data.(map[string]interface{})[key]; ok { diff --git a/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go b/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go index 9bb9c33d3..3fdf751cd 100644 --- a/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go +++ b/vendor/github.com/hashicorp/packer-plugin-sdk/version/version.go @@ -13,12 +13,12 @@ import ( var GitCommit string // Package version helps plugin creators set and track the sdk version using -var Version = "0.0.14" +var Version = "0.1.1" // A pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release // such as "dev" (in development), "beta", "rc1", etc. -var VersionPrerelease = "" +var VersionPrerelease = "dev" // SDKVersion is used by the plugin set to allow Packer to recognize // what version of the sdk the plugin is. diff --git a/vendor/modules.txt b/vendor/modules.txt index 3836bdf3a..49143ddb0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -428,7 +428,7 @@ github.com/hashicorp/packer-plugin-docker/post-processor/docker-import github.com/hashicorp/packer-plugin-docker/post-processor/docker-push github.com/hashicorp/packer-plugin-docker/post-processor/docker-save github.com/hashicorp/packer-plugin-docker/post-processor/docker-tag -# github.com/hashicorp/packer-plugin-sdk v0.0.14 +# github.com/hashicorp/packer-plugin-sdk v0.1.1-0.20210323111710-5a7ab7f7a1c0 ## explicit github.com/hashicorp/packer-plugin-sdk/acctest github.com/hashicorp/packer-plugin-sdk/acctest/provisioneracc @@ -440,6 +440,7 @@ github.com/hashicorp/packer-plugin-sdk/common github.com/hashicorp/packer-plugin-sdk/communicator github.com/hashicorp/packer-plugin-sdk/communicator/ssh github.com/hashicorp/packer-plugin-sdk/communicator/sshkey +github.com/hashicorp/packer-plugin-sdk/didyoumean github.com/hashicorp/packer-plugin-sdk/filelock github.com/hashicorp/packer-plugin-sdk/guestexec github.com/hashicorp/packer-plugin-sdk/hcl2helper diff --git a/website/content/docs/builders/cloudstack.mdx b/website/content/docs/builders/cloudstack.mdx index 149370e23..55e0c74c9 100644 --- a/website/content/docs/builders/cloudstack.mdx +++ b/website/content/docs/builders/cloudstack.mdx @@ -89,25 +89,10 @@ builder. - `expunge` (boolean) - Set to `true` to expunge the instance when it is destroyed. Defaults to `false`. -- `http_directory` (string) - Path to a directory to serve using an HTTP - server. The files in this directory will be available over HTTP that will - be requestable from the virtual machine. This is useful for hosting - kickstart files and so on. By default this is "", which means no HTTP - server will be started. The address and port of the HTTP server will be - available as variables in `user_data`. This is covered in more detail - below. - - `http_get_only` (boolean) - Some cloud providers only allow HTTP GET calls to their CloudStack API. If using such a provider, you need to set this to `true` in order for the provider to only make GET calls and no POST calls. -- `http_port_min` and `http_port_max` (number) - These are the minimum and - maximum port to use for the HTTP server started to serve the - `http_directory`. Because Packer often runs in parallel, Packer will choose - a randomly available port in this range to run the HTTP server. If you want - to force the HTTP server to be on one port, make this minimum and maximum - port the same. By default the values are 8000 and 9000, respectively. - - `hypervisor` (string) - The target hypervisor (e.g. `XenServer`, `KVM`) for the new template. This option is required when using `source_iso`. diff --git a/website/content/docs/builders/parallels/iso.mdx b/website/content/docs/builders/parallels/iso.mdx index b974064cd..fa49e7b91 100644 --- a/website/content/docs/builders/parallels/iso.mdx +++ b/website/content/docs/builders/parallels/iso.mdx @@ -146,20 +146,6 @@ can also be supplied to override the typical auto-generated key: \["en0", "en1", "en2", "en3", "en4", "en5", "en6", "en7", "en8", "en9", "ppp0", "ppp1", "ppp2"\]. -- `http_directory` (string) - Path to a directory to serve using an - HTTP server. The files in this directory will be available over HTTP that - will be requestable from the virtual machine. This is useful for hosting - kickstart files and so on. By default this is "", which means no HTTP server - will be started. The address and port of the HTTP server will be available - as variables in `boot_command`. This is covered in more detail below. - -- `http_port_min` and `http_port_max` (number) - These are the minimum and - maximum port to use for the HTTP server started to serve the - `http_directory`. Because Packer often runs in parallel, Packer will choose - a randomly available port in this range to run the HTTP server. If you want - to force the HTTP server to be on one port, make this minimum and maximum - port the same. By default the values are 8000 and 9000, respectively. - - `memory` (number) - The amount of memory to use for building the VM in megabytes. Defaults to `512` megabytes. @@ -231,6 +217,14 @@ can also be supplied to override the typical auto-generated key: virtual machine, without the file extension. By default this is "packer-BUILDNAME", where "BUILDNAME" is the name of the build. +## Http directory configuration reference + +@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig.mdx' + +### Optional: + +@include 'packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx' + ## Boot Command The `boot_command` configuration is very important: it specifies the keys to diff --git a/website/content/docs/provisioners/file.mdx b/website/content/docs/provisioners/file.mdx index e65002898..b2bc1bfe2 100644 --- a/website/content/docs/provisioners/file.mdx +++ b/website/content/docs/provisioners/file.mdx @@ -180,11 +180,10 @@ build { ## Slowness when transferring large files over WinRM. Because of the way our WinRM transfers works, it can take a very long time to -upload and download even moderately sized files. If you're experiencing -slowness using the file provisioner on Windows, it's suggested that you set up -an SSH server and use the [ssh -communicator](/docs/communicators/ssh). If you only -want to transfer files to your guest, and if your builder supports it, you may -also use the `http_directory` directive. This will cause that directory to be -available to the guest over http, and set the environment variable -`PACKER_HTTP_ADDR` to the address. +upload and download even moderately sized files. If you're experiencing slowness +using the file provisioner on Windows, it's suggested that you set up an SSH +server and use the [ssh communicator](/docs/communicators/ssh). If you only want +to transfer files to your guest, and if your builder supports it, you may also +use the `http_directory` or `http_content` directives. This will cause that +directory to be available to the guest over http, and set the environment +variable `PACKER_HTTP_ADDR` to the address. diff --git a/website/content/guides/automatic-operating-system-installs/preseed_ubuntu.mdx b/website/content/guides/automatic-operating-system-installs/preseed_ubuntu.mdx index dbcb3e40a..bb218f4ff 100644 --- a/website/content/guides/automatic-operating-system-installs/preseed_ubuntu.mdx +++ b/website/content/guides/automatic-operating-system-installs/preseed_ubuntu.mdx @@ -41,10 +41,10 @@ comment or uncomment the options as you need them. ## Where to put the preseed file -The `-iso` builders mentioned above all have an `http_dir` option. Any file -inside of your `http_dir` will be served on a local fileserver for your virtual -machine to be able to access. One very common use for this directory is to use -it to provide your preseed file. +The `-iso` builders mentioned above all have an `http_dir` or an `http_content` +option. Any file inside of your `http_dir` or `http_content` will be served on a +local fileserver for your virtual machine to be able to access. One very common +use for this directory is to use it to provide your preseed file. You then reference the file using a `boot_command` to kick off the installation. In the example below, see how the `preseed/url` command line option is being diff --git a/website/content/partials/builders/boot-command.mdx b/website/content/partials/builders/boot-command.mdx index 1cd77193e..625984915 100644 --- a/website/content/partials/builders/boot-command.mdx +++ b/website/content/partials/builders/boot-command.mdx @@ -60,8 +60,8 @@ available variables are: - `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server that is started serving the directory specified by the `http_directory` - configuration parameter. If `http_directory` isn't specified, these will be - blank! + configuration parameter or the content specified in the `http_content` map. If + `http_directory` or `http_content` isn't specified, these will be blank! - `Name` - The name of the VM. For more examples of various boot commands, see the sample projects from our diff --git a/website/content/partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx b/website/content/partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx index c8a364003..1d5d59d5c 100644 --- a/website/content/partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx +++ b/website/content/partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx @@ -7,6 +7,15 @@ started. The address and port of the HTTP server will be available as variables in `boot_command`. This is covered in more detail below. +- `http_content` (map[string]string) - Key/Values to serve using an HTTP server. http_content works like and + conflicts with http_directory The keys represent the paths and the values + contents. This is useful for hosting kickstart files and so on. By + default this is empty, which means no HTTP server will be started. The + address and port of the HTTP server will be available as variables in + `boot_command`. This is covered in more detail below. Example: Setting + `"foo/bar"="baz"`, will allow you to http get on + `http://{http_ip}:{http_port}/foo/bar`. + - `http_port_min` (int) - These are the minimum and maximum port to use for the HTTP server started to serve the `http_directory`. Because Packer often runs in parallel, Packer will choose a randomly available port in this range to