diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index 0c7d0aaab..23ca9d7bb 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/packer/builder" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/hcl2template" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" @@ -54,7 +55,12 @@ type Config struct { // duplicated in `tags`. This is a [template // engine](/docs/templates/engine), see [Build template // data](#build-template-data) for more information. - VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"` + VolumeRunTags map[string]string `mapstructure:"run_volume_tags"` + // Same as [`run_volume_tags`](#run_volume_tags) but defined as a singular + // block containing a `name` and a `value` field. In HCL2 mode the + // [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks) + // will allow you to create those programatically. + VolumeRunTag hcl2template.NameValues `mapstructure:"run_volume_tag" required:"false"` // Relevant only to Windows guests: If you set this flag, we'll add clauses // to the launch_block_device_mappings that make sure ephemeral drives // don't show up in the EC2 console. If you launched from the EC2 console, @@ -104,6 +110,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { var errs *packer.MultiError var warns []string + errs = packer.MultiErrorAppend(errs, b.config.VolumeRunTag.CopyOn(&b.config.VolumeRunTags)...) + errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.AMIConfig.Prepare(&b.config.AccessConfig, &b.config.ctx)...) diff --git a/builder/amazon/ebs/builder.hcl2spec.go b/builder/amazon/ebs/builder.hcl2spec.go index 699574ce7..d68eae53e 100644 --- a/builder/amazon/ebs/builder.hcl2spec.go +++ b/builder/amazon/ebs/builder.hcl2spec.go @@ -131,7 +131,8 @@ type FlatConfig struct { SessionManagerPort *int `mapstructure:"session_manager_port" cty:"session_manager_port" hcl:"session_manager_port"` AMIMappings []common.FlatBlockDevice `mapstructure:"ami_block_device_mappings" required:"false" cty:"ami_block_device_mappings" hcl:"ami_block_device_mappings"` LaunchMappings []common.FlatBlockDevice `mapstructure:"launch_block_device_mappings" required:"false" cty:"launch_block_device_mappings" hcl:"launch_block_device_mappings"` - VolumeRunTags common.TagMap `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` + VolumeRunTags map[string]string `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` + VolumeRunTag []hcl2template.FlatNameValue `mapstructure:"run_volume_tag" required:"false" cty:"run_volume_tag" hcl:"run_volume_tag"` NoEphemeral *bool `mapstructure:"no_ephemeral" required:"false" cty:"no_ephemeral" hcl:"no_ephemeral"` } @@ -268,6 +269,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "ami_block_device_mappings": &hcldec.BlockListSpec{TypeName: "ami_block_device_mappings", Nested: hcldec.ObjectSpec((*common.FlatBlockDevice)(nil).HCL2Spec())}, "launch_block_device_mappings": &hcldec.BlockListSpec{TypeName: "launch_block_device_mappings", Nested: hcldec.ObjectSpec((*common.FlatBlockDevice)(nil).HCL2Spec())}, "run_volume_tags": &hcldec.AttrSpec{Name: "run_volume_tags", Type: cty.Map(cty.String), Required: false}, + "run_volume_tag": &hcldec.BlockListSpec{TypeName: "run_volume_tag", Nested: hcldec.ObjectSpec((*hcl2template.FlatNameValue)(nil).HCL2Spec())}, "no_ephemeral": &hcldec.AttrSpec{Name: "no_ephemeral", Type: cty.Bool, Required: false}, } return s diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index 2a60bcd76..3761bfa1c 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/packer/builder" awscommon "github.com/hashicorp/packer/builder/amazon/common" "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/hcl2template" "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" @@ -60,7 +61,12 @@ type Config struct { // duplicated in `tags`. This is a [template // engine](/docs/templates/engine), see [Build template // data](#build-template-data) for more information. - VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"` + VolumeRunTags map[string]string `mapstructure:"run_volume_tags"` + // Same as [`run_volume_tags`](#run_volume_tags) but defined as a singular + // block containing a `name` and a `value` field. In HCL2 mode the + // [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks) + // will allow you to create those programatically. + VolumeRunTag hcl2template.NameValues `mapstructure:"run_volume_tag" required:"false"` // what architecture to use when registering the // final AMI; valid options are "x86_64" or "arm64". Defaults to "x86_64". Architecture string `mapstructure:"ami_architecture" required:"false"` @@ -102,6 +108,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) { // Accumulate any errors var errs *packer.MultiError var warns []string + errs = packer.MultiErrorAppend(errs, b.config.VolumeRunTag.CopyOn(&b.config.VolumeRunTags)...) + errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...) errs = packer.MultiErrorAppend(errs, diff --git a/builder/amazon/ebssurrogate/builder.hcl2spec.go b/builder/amazon/ebssurrogate/builder.hcl2spec.go index c4523dab8..6e678a4a3 100644 --- a/builder/amazon/ebssurrogate/builder.hcl2spec.go +++ b/builder/amazon/ebssurrogate/builder.hcl2spec.go @@ -175,7 +175,8 @@ type FlatConfig struct { AMIMappings []common.FlatBlockDevice `mapstructure:"ami_block_device_mappings" required:"false" cty:"ami_block_device_mappings" hcl:"ami_block_device_mappings"` LaunchMappings []FlatBlockDevice `mapstructure:"launch_block_device_mappings" required:"false" cty:"launch_block_device_mappings" hcl:"launch_block_device_mappings"` RootDevice *FlatRootBlockDevice `mapstructure:"ami_root_device" required:"true" cty:"ami_root_device" hcl:"ami_root_device"` - VolumeRunTags common.TagMap `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` + VolumeRunTags map[string]string `mapstructure:"run_volume_tags" cty:"run_volume_tags" hcl:"run_volume_tags"` + VolumeRunTag []hcl2template.FlatNameValue `mapstructure:"run_volume_tag" required:"false" cty:"run_volume_tag" hcl:"run_volume_tag"` Architecture *string `mapstructure:"ami_architecture" required:"false" cty:"ami_architecture" hcl:"ami_architecture"` } @@ -313,6 +314,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "launch_block_device_mappings": &hcldec.BlockListSpec{TypeName: "launch_block_device_mappings", Nested: hcldec.ObjectSpec((*FlatBlockDevice)(nil).HCL2Spec())}, "ami_root_device": &hcldec.BlockSpec{TypeName: "ami_root_device", Nested: hcldec.ObjectSpec((*FlatRootBlockDevice)(nil).HCL2Spec())}, "run_volume_tags": &hcldec.AttrSpec{Name: "run_volume_tags", Type: cty.Map(cty.String), Required: false}, + "run_volume_tag": &hcldec.BlockListSpec{TypeName: "run_volume_tag", Nested: hcldec.ObjectSpec((*hcl2template.FlatNameValue)(nil).HCL2Spec())}, "ami_architecture": &hcldec.AttrSpec{Name: "ami_architecture", Type: cty.String, Required: false}, } return s diff --git a/website/pages/partials/builder/amazon/ebs/Config-not-required.mdx b/website/pages/partials/builder/amazon/ebs/Config-not-required.mdx index d57aa3c30..4a6b23506 100644 --- a/website/pages/partials/builder/amazon/ebs/Config-not-required.mdx +++ b/website/pages/partials/builder/amazon/ebs/Config-not-required.mdx @@ -16,12 +16,17 @@ from the source instance. See the [BlockDevices](#block-devices-configuration) documentation for fields. -- `run_volume_tags` (awscommon.TagMap) - Tags to apply to the volumes that are *launched* to create the AMI. +- `run_volume_tags` (map[string]string) - Tags to apply to the volumes that are *launched* to create the AMI. These tags are *not* applied to the resulting AMI unless they're duplicated in `tags`. This is a [template engine](/docs/templates/engine), see [Build template data](#build-template-data) for more information. +- `run_volume_tag` ([]{name string, value string}) - Same as [`run_volume_tags`](#run_volume_tags) but defined as a singular + block containing a `name` and a `value` field. In HCL2 mode the + [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks) + will allow you to create those programatically. + - `no_ephemeral` (bool) - Relevant only to Windows guests: If you set this flag, we'll add clauses to the launch_block_device_mappings that make sure ephemeral drives don't show up in the EC2 console. If you launched from the EC2 console, diff --git a/website/pages/partials/builder/amazon/ebssurrogate/Config-not-required.mdx b/website/pages/partials/builder/amazon/ebssurrogate/Config-not-required.mdx index ffa5ec78a..499b82ee7 100644 --- a/website/pages/partials/builder/amazon/ebssurrogate/Config-not-required.mdx +++ b/website/pages/partials/builder/amazon/ebssurrogate/Config-not-required.mdx @@ -16,12 +16,17 @@ from the source instance. See the [BlockDevices](#block-devices-configuration) documentation for fields. -- `run_volume_tags` (awscommon.TagMap) - Tags to apply to the volumes that are *launched* to create the AMI. +- `run_volume_tags` (map[string]string) - Tags to apply to the volumes that are *launched* to create the AMI. These tags are *not* applied to the resulting AMI unless they're duplicated in `tags`. This is a [template engine](/docs/templates/engine), see [Build template data](#build-template-data) for more information. +- `run_volume_tag` ([]{name string, value string}) - Same as [`run_volume_tags`](#run_volume_tags) but defined as a singular + block containing a `name` and a `value` field. In HCL2 mode the + [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks) + will allow you to create those programatically. + - `ami_architecture` (string) - what architecture to use when registering the final AMI; valid options are "x86_64" or "arm64". Defaults to "x86_64". \ No newline at end of file