From 29f31986ac19499dbad8c657453bcca77dca7133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Este-Gracias?= Date: Fri, 1 Oct 2021 19:13:18 +0200 Subject: [PATCH 1/2] Support floppy_content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Este-Gracias --- builder/vsphere/clone/builder.go | 1 + builder/vsphere/clone/config.hcl2spec.go | 2 ++ builder/vsphere/common/step_add_floppy.go | 15 +++++++++++++++ .../vsphere/common/step_add_floppy.hcl2spec.go | 10 ++++++---- builder/vsphere/iso/builder.go | 1 + builder/vsphere/iso/config.hcl2spec.go | 2 ++ .../vsphere/common/FloppyConfig-not-required.mdx | 15 +++++++++++++++ 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/builder/vsphere/clone/builder.go b/builder/vsphere/clone/builder.go index b3e6f452..6e440b0b 100644 --- a/builder/vsphere/clone/builder.go +++ b/builder/vsphere/clone/builder.go @@ -78,6 +78,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) &commonsteps.StepCreateFloppy{ Files: b.config.FloppyFiles, Directories: b.config.FloppyDirectories, + Content: b.config.FloppyContent, Label: b.config.FloppyLabel, }, &common.StepAddFloppy{ diff --git a/builder/vsphere/clone/config.hcl2spec.go b/builder/vsphere/clone/config.hcl2spec.go index 8f90e2a4..ea8ce44f 100644 --- a/builder/vsphere/clone/config.hcl2spec.go +++ b/builder/vsphere/clone/config.hcl2spec.go @@ -72,6 +72,7 @@ type FlatConfig struct { FloppyIMGPath *string `mapstructure:"floppy_img_path" cty:"floppy_img_path" hcl:"floppy_img_path"` FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files" hcl:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs" hcl:"floppy_dirs"` + FloppyContent map[string]string `mapstructure:"floppy_content" cty:"floppy_content" hcl:"floppy_content"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label" hcl:"floppy_label"` BootOrder *string `mapstructure:"boot_order" cty:"boot_order" hcl:"boot_order"` BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval" hcl:"boot_keygroup_interval"` @@ -214,6 +215,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "floppy_img_path": &hcldec.AttrSpec{Name: "floppy_img_path", Type: cty.String, Required: false}, "floppy_files": &hcldec.AttrSpec{Name: "floppy_files", Type: cty.List(cty.String), Required: false}, "floppy_dirs": &hcldec.AttrSpec{Name: "floppy_dirs", Type: cty.List(cty.String), Required: false}, + "floppy_content": &hcldec.AttrSpec{Name: "floppy_content", Type: cty.Map(cty.String), Required: false}, "floppy_label": &hcldec.AttrSpec{Name: "floppy_label", Type: cty.String, Required: false}, "boot_order": &hcldec.AttrSpec{Name: "boot_order", Type: cty.String, Required: false}, "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, diff --git a/builder/vsphere/common/step_add_floppy.go b/builder/vsphere/common/step_add_floppy.go index 0df37b68..65f612a0 100644 --- a/builder/vsphere/common/step_add_floppy.go +++ b/builder/vsphere/common/step_add_floppy.go @@ -21,6 +21,21 @@ type FloppyConfig struct { FloppyFiles []string `mapstructure:"floppy_files"` // List of directories to copy files from. FloppyDirectories []string `mapstructure:"floppy_dirs"` + // Key/Values to add to the floppy disk. The keys represent the paths, and + // the values contents. It can be used alongside `floppy_files` or + // `floppy_dirs`, which is useful to add large files without loading them + // into memory. If any paths are specified by both, the contents in + // `floppy_content` will take precedence. + // + // Usage example (HCL): + // + // ```hcl + // floppy_content = { + // "meta-data" = jsonencode(local.instance_data) + // "user-data" = templatefile("user-data", { packages = ["nginx"] }) + // } + // ``` + FloppyContent map[string]string `mapstructure:"floppy_content"` // The label to use for the floppy disk that // is attached when the VM is booted. This is most useful for cloud-init, // Kickstart or other early initialization tools, which can benefit from labelled floppy disks. diff --git a/builder/vsphere/common/step_add_floppy.hcl2spec.go b/builder/vsphere/common/step_add_floppy.hcl2spec.go index 0a383056..c3fe8229 100644 --- a/builder/vsphere/common/step_add_floppy.hcl2spec.go +++ b/builder/vsphere/common/step_add_floppy.hcl2spec.go @@ -10,10 +10,11 @@ import ( // FlatFloppyConfig is an auto-generated flat version of FloppyConfig. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatFloppyConfig struct { - FloppyIMGPath *string `mapstructure:"floppy_img_path" cty:"floppy_img_path" hcl:"floppy_img_path"` - FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files" hcl:"floppy_files"` - FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs" hcl:"floppy_dirs"` - FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label" hcl:"floppy_label"` + FloppyIMGPath *string `mapstructure:"floppy_img_path" cty:"floppy_img_path" hcl:"floppy_img_path"` + FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files" hcl:"floppy_files"` + FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs" hcl:"floppy_dirs"` + FloppyContent map[string]string `mapstructure:"floppy_content" cty:"floppy_content" hcl:"floppy_content"` + FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label" hcl:"floppy_label"` } // FlatMapstructure returns a new FlatFloppyConfig. @@ -31,6 +32,7 @@ func (*FlatFloppyConfig) HCL2Spec() map[string]hcldec.Spec { "floppy_img_path": &hcldec.AttrSpec{Name: "floppy_img_path", Type: cty.String, Required: false}, "floppy_files": &hcldec.AttrSpec{Name: "floppy_files", Type: cty.List(cty.String), Required: false}, "floppy_dirs": &hcldec.AttrSpec{Name: "floppy_dirs", Type: cty.List(cty.String), Required: false}, + "floppy_content": &hcldec.AttrSpec{Name: "floppy_content", Type: cty.Map(cty.String), Required: false}, "floppy_label": &hcldec.AttrSpec{Name: "floppy_label", Type: cty.String, Required: false}, } return s diff --git a/builder/vsphere/iso/builder.go b/builder/vsphere/iso/builder.go index 06f1bcca..5179e6cf 100644 --- a/builder/vsphere/iso/builder.go +++ b/builder/vsphere/iso/builder.go @@ -81,6 +81,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) &commonsteps.StepCreateFloppy{ Files: b.config.FloppyFiles, Directories: b.config.FloppyDirectories, + Content: b.config.FloppyContent, Label: b.config.FloppyLabel, }, &common.StepAddFloppy{ diff --git a/builder/vsphere/iso/config.hcl2spec.go b/builder/vsphere/iso/config.hcl2spec.go index 6337970b..b28639c8 100644 --- a/builder/vsphere/iso/config.hcl2spec.go +++ b/builder/vsphere/iso/config.hcl2spec.go @@ -75,6 +75,7 @@ type FlatConfig struct { FloppyIMGPath *string `mapstructure:"floppy_img_path" cty:"floppy_img_path" hcl:"floppy_img_path"` FloppyFiles []string `mapstructure:"floppy_files" cty:"floppy_files" hcl:"floppy_files"` FloppyDirectories []string `mapstructure:"floppy_dirs" cty:"floppy_dirs" hcl:"floppy_dirs"` + FloppyContent map[string]string `mapstructure:"floppy_content" cty:"floppy_content" hcl:"floppy_content"` FloppyLabel *string `mapstructure:"floppy_label" cty:"floppy_label" hcl:"floppy_label"` BootOrder *string `mapstructure:"boot_order" cty:"boot_order" hcl:"boot_order"` BootGroupInterval *string `mapstructure:"boot_keygroup_interval" cty:"boot_keygroup_interval" hcl:"boot_keygroup_interval"` @@ -219,6 +220,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "floppy_img_path": &hcldec.AttrSpec{Name: "floppy_img_path", Type: cty.String, Required: false}, "floppy_files": &hcldec.AttrSpec{Name: "floppy_files", Type: cty.List(cty.String), Required: false}, "floppy_dirs": &hcldec.AttrSpec{Name: "floppy_dirs", Type: cty.List(cty.String), Required: false}, + "floppy_content": &hcldec.AttrSpec{Name: "floppy_content", Type: cty.Map(cty.String), Required: false}, "floppy_label": &hcldec.AttrSpec{Name: "floppy_label", Type: cty.String, Required: false}, "boot_order": &hcldec.AttrSpec{Name: "boot_order", Type: cty.String, Required: false}, "boot_keygroup_interval": &hcldec.AttrSpec{Name: "boot_keygroup_interval", Type: cty.String, Required: false}, diff --git a/docs-partials/builder/vsphere/common/FloppyConfig-not-required.mdx b/docs-partials/builder/vsphere/common/FloppyConfig-not-required.mdx index 0794c8c2..93095262 100644 --- a/docs-partials/builder/vsphere/common/FloppyConfig-not-required.mdx +++ b/docs-partials/builder/vsphere/common/FloppyConfig-not-required.mdx @@ -8,6 +8,21 @@ - `floppy_dirs` ([]string) - List of directories to copy files from. +- `floppy_content` (map[string]string) - Key/Values to add to the floppy disk. The keys represent the paths, and + the values contents. It can be used alongside `floppy_files` or + `floppy_dirs`, which is useful to add large files without loading them + into memory. If any paths are specified by both, the contents in + `floppy_content` will take precedence. + + Usage example (HCL): + + ```hcl + floppy_content = { + "meta-data" = jsonencode(local.instance_data) + "user-data" = templatefile("user-data", { packages = ["nginx"] }) + } + ``` + - `floppy_label` (string) - The label to use for the floppy disk that is attached when the VM is booted. This is most useful for cloud-init, Kickstart or other early initialization tools, which can benefit from labelled floppy disks. From e4f0e1ca5145491e026222db596bffa59982aec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ste=CC=81phane=20Este-Gracias?= Date: Fri, 8 Oct 2021 17:08:15 +0200 Subject: [PATCH 2/2] Update packer-plugin-sdk to v0.2.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Este-Gracias --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index fe16832f..08f0cbba 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.17 require ( github.com/google/go-cmp v0.5.6 github.com/hashicorp/hcl/v2 v2.10.1 - github.com/hashicorp/packer-plugin-sdk v0.2.5 + github.com/hashicorp/packer-plugin-sdk v0.2.7 github.com/pkg/errors v0.9.1 github.com/vmware/govmomi v0.24.1 github.com/zclconf/go-cty v1.9.1 diff --git a/go.sum b/go.sum index b46f243c..1a923473 100644 --- a/go.sum +++ b/go.sum @@ -338,6 +338,8 @@ github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/packer-plugin-sdk v0.2.5 h1:qydxm7rbyUuUvvh2rxTZjur8kG5JQNGtpOifS4Xv1BY= github.com/hashicorp/packer-plugin-sdk v0.2.5/go.mod h1:ii9ub5UNAp30RGod3i3W8qj7wA+H7kpURnD+Jt7oDkQ= +github.com/hashicorp/packer-plugin-sdk v0.2.7 h1:L7mfLg+gGnqN3z8vEG4YojVsbhYJrNcimvOSIuCN6qA= +github.com/hashicorp/packer-plugin-sdk v0.2.7/go.mod h1:ii9ub5UNAp30RGod3i3W8qj7wA+H7kpURnD+Jt7oDkQ= github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM= github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/hashicorp/vault/api v1.0.5-0.20200519221902-385fac77e20f/go.mod h1:euTFbi2YJgwcju3imEt919lhJKF68nN1cQPq3aA+kBE=