From 0a29c356b972df2e6475b19f8b6502fd7f1e8973 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Wed, 27 Mar 2024 18:06:01 +0100 Subject: [PATCH 1/3] feat(ebs): Feature to create vm without snapshot --- builder/bsu/builder.go | 37 +++++++++++++++++++-------------- builder/bsu/builder.hcl2spec.go | 2 ++ docs/builders/bsu.mdx | 3 +++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/builder/bsu/builder.go b/builder/bsu/builder.go index 08788784..620f8924 100644 --- a/builder/bsu/builder.go +++ b/builder/bsu/builder.go @@ -32,6 +32,7 @@ type Config struct { osccommon.BlockDevices `mapstructure:",squash"` osccommon.RunConfig `mapstructure:",squash"` VolumeRunTags osccommon.TagMap `mapstructure:"run_volume_tags"` + SkipSnapshot bool `mapstructure:"skip_snapshot"` ctx interpolate.Context } @@ -181,22 +182,26 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) OMIName: b.config.OMIName, Regions: b.config.OMIRegions, }, - &stepCreateOMI{ - RawRegion: b.config.RawRegion, - ProductCodes: b.config.ProductCodes, - }, - &osccommon.StepUpdateOMIAttributes{ - AccountIds: b.config.OMIAccountIDs, - SnapshotAccountIds: b.config.SnapshotAccountIDs, - RawRegion: b.config.RawRegion, - GlobalPermission: b.config.GlobalPermission, - Ctx: b.config.ctx, - }, - &osccommon.StepCreateTags{ - Tags: b.config.OMITags, - SnapshotTags: b.config.SnapshotTags, - Ctx: b.config.ctx, - }, + } + + if !b.config.SkipSnapshot { + steps = append(steps, + &stepCreateOMI{ + RawRegion: b.config.RawRegion, + ProductCodes: b.config.ProductCodes, + }, + &osccommon.StepUpdateOMIAttributes{ + AccountIds: b.config.OMIAccountIDs, + SnapshotAccountIds: b.config.SnapshotAccountIDs, + RawRegion: b.config.RawRegion, + GlobalPermission: b.config.GlobalPermission, + Ctx: b.config.ctx, + }, + &osccommon.StepCreateTags{ + Tags: b.config.OMITags, + SnapshotTags: b.config.SnapshotTags, + Ctx: b.config.ctx, + }) } b.runner = commonsteps.NewRunner(steps, b.config.PackerConfig, ui) diff --git a/builder/bsu/builder.hcl2spec.go b/builder/bsu/builder.hcl2spec.go index 6b1e51b4..aa962c8a 100644 --- a/builder/bsu/builder.hcl2spec.go +++ b/builder/bsu/builder.hcl2spec.go @@ -120,6 +120,7 @@ type FlatConfig struct { WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm" hcl:"winrm_use_ntlm"` SSHInterface *string `mapstructure:"ssh_interface" cty:"ssh_interface" hcl:"ssh_interface"` VolumeRunTags common.TagMap `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` + SkipSnapshot *bool `mapstructure:"skip_snapshot" cty:"skip_snapshot" hcl:"skip_snapshot"` } // FlatMapstructure returns a new FlatConfig. @@ -243,6 +244,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false}, "ssh_interface": &hcldec.AttrSpec{Name: "ssh_interface", Type: cty.String, Required: false}, "run_volume_tags": &hcldec.AttrSpec{Name: "run_volume_tags", Type: cty.Map(cty.String), Required: false}, + "skip_snapshot": &hcldec.AttrSpec{ Name: "skip_snapshot", Type: cty.Bool, Required: false }, } return s } diff --git a/docs/builders/bsu.mdx b/docs/builders/bsu.mdx index d6663427..0673ac3a 100644 --- a/docs/builders/bsu.mdx +++ b/docs/builders/bsu.mdx @@ -162,6 +162,9 @@ builder. - `skip_region_validation` (boolean) - Set to true if you want to skip validation of the region configuration option. Default `false`. +- `skip_snapshot` (boolean) - Set to true if you want to skip snapshot creation. + No image will be created if set to true. Default `false`. + - `snapshot_groups` (array of strings) - A list of groups that have access to create volumes from the snapshot(s). By default no groups have permission to create volumes from the snapshot(s). `all` will make the snapshot From 0a009ef4ca39b9a96af5be9432c213faeff68348 Mon Sep 17 00:00:00 2001 From: Lilian Deloche Date: Tue, 2 Apr 2024 16:15:57 +0200 Subject: [PATCH 2/3] feat(bsu): rename option to skip_create_omi --- builder/bsu/builder.go | 4 ++-- builder/bsu/builder.hcl2spec.go | 4 ++-- docs/builders/bsu.mdx | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/builder/bsu/builder.go b/builder/bsu/builder.go index 620f8924..d78b4d94 100644 --- a/builder/bsu/builder.go +++ b/builder/bsu/builder.go @@ -32,7 +32,7 @@ type Config struct { osccommon.BlockDevices `mapstructure:",squash"` osccommon.RunConfig `mapstructure:",squash"` VolumeRunTags osccommon.TagMap `mapstructure:"run_volume_tags"` - SkipSnapshot bool `mapstructure:"skip_snapshot"` + SkipCreateOmi bool `mapstructure:"skip_create_omi"` ctx interpolate.Context } @@ -184,7 +184,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook) }, } - if !b.config.SkipSnapshot { + if !b.config.SkipCreateOmi { steps = append(steps, &stepCreateOMI{ RawRegion: b.config.RawRegion, diff --git a/builder/bsu/builder.hcl2spec.go b/builder/bsu/builder.hcl2spec.go index aa962c8a..38a76d39 100644 --- a/builder/bsu/builder.hcl2spec.go +++ b/builder/bsu/builder.hcl2spec.go @@ -120,7 +120,7 @@ type FlatConfig struct { WinRMUseNTLM *bool `mapstructure:"winrm_use_ntlm" cty:"winrm_use_ntlm" hcl:"winrm_use_ntlm"` SSHInterface *string `mapstructure:"ssh_interface" cty:"ssh_interface" hcl:"ssh_interface"` VolumeRunTags common.TagMap `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` - SkipSnapshot *bool `mapstructure:"skip_snapshot" cty:"skip_snapshot" hcl:"skip_snapshot"` + SkipCreateOmi *bool `mapstructure:"skip_create_omi" cty:"skip_create_omi" hcl:"skip_create_omi"` } // FlatMapstructure returns a new FlatConfig. @@ -244,7 +244,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false}, "ssh_interface": &hcldec.AttrSpec{Name: "ssh_interface", Type: cty.String, Required: false}, "run_volume_tags": &hcldec.AttrSpec{Name: "run_volume_tags", Type: cty.Map(cty.String), Required: false}, - "skip_snapshot": &hcldec.AttrSpec{ Name: "skip_snapshot", Type: cty.Bool, Required: false }, + "skip_create_omi": &hcldec.AttrSpec{Name: "skip_create_omi", Type: cty.Bool, Required: false}, } return s } diff --git a/docs/builders/bsu.mdx b/docs/builders/bsu.mdx index 0673ac3a..875694ba 100644 --- a/docs/builders/bsu.mdx +++ b/docs/builders/bsu.mdx @@ -159,12 +159,12 @@ builder. shutdown in case Packer exits ungracefully. Possible values are "stop" and "terminate", default is `stop`. +- `skip_create_omi` (boolean) - Set to true if you want to skip snapshot creation. + No image will be created if set to true. Default `false`. + - `skip_region_validation` (boolean) - Set to true if you want to skip validation of the region configuration option. Default `false`. -- `skip_snapshot` (boolean) - Set to true if you want to skip snapshot creation. - No image will be created if set to true. Default `false`. - - `snapshot_groups` (array of strings) - A list of groups that have access to create volumes from the snapshot(s). By default no groups have permission to create volumes from the snapshot(s). `all` will make the snapshot From 8a9dde8550dc76f0ce16b6973dc014a5288bba23 Mon Sep 17 00:00:00 2001 From: "matthias.gatto" Date: Mon, 8 Apr 2024 10:32:51 +0200 Subject: [PATCH 3/3] Documentation: make generate Signed-off-by: matthias.gatto --- .web-docs/components/builder/bsu/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.web-docs/components/builder/bsu/README.md b/.web-docs/components/builder/bsu/README.md index d16f3901..299979d7 100644 --- a/.web-docs/components/builder/bsu/README.md +++ b/.web-docs/components/builder/bsu/README.md @@ -145,6 +145,9 @@ builder. shutdown in case Packer exits ungracefully. Possible values are "stop" and "terminate", default is `stop`. +- `skip_create_omi` (boolean) - Set to true if you want to skip snapshot creation. + No image will be created if set to true. Default `false`. + - `skip_region_validation` (boolean) - Set to true if you want to skip validation of the region configuration option. Default `false`.