wip
This commit is contained in:
parent
c845436e32
commit
d532bb376c
|
@ -163,7 +163,7 @@ type Config struct {
|
||||||
// Tags to apply to the volumes that are *launched*. This is a [template
|
// Tags to apply to the volumes that are *launched*. This is a [template
|
||||||
// engine](/docs/templates/engine.html), see [Build template
|
// engine](/docs/templates/engine.html), see [Build template
|
||||||
// data](#build-template-data) for more information.
|
// data](#build-template-data) for more information.
|
||||||
RootVolumeTags awscommon.TagMap `mapstructure:"root_volume_tags" required:"false"`
|
RootVolumeTags map[string]string `mapstructure:"root_volume_tags" required:"false"`
|
||||||
// Same as [`root_volume_tags`](#root_volume_tags) but defined as a
|
// Same as [`root_volume_tags`](#root_volume_tags) but defined as a
|
||||||
// singular block containing a key and a value field. In HCL2 mode the
|
// singular block containing a key and a value field. In HCL2 mode the
|
||||||
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
||||||
|
|
|
@ -26,7 +26,7 @@ type FlatConfig struct {
|
||||||
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
||||||
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
||||||
AMISkipRegionValidation *bool `mapstructure:"skip_region_validation" required:"false" cty:"skip_region_validation"`
|
AMISkipRegionValidation *bool `mapstructure:"skip_region_validation" required:"false" cty:"skip_region_validation"`
|
||||||
AMITags common.TagMap `mapstructure:"tags" required:"false" cty:"tags"`
|
AMITags map[string]string `mapstructure:"tags" required:"false" cty:"tags"`
|
||||||
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
||||||
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
||||||
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
||||||
|
@ -36,7 +36,7 @@ type FlatConfig struct {
|
||||||
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
||||||
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
||||||
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
||||||
SnapshotTags common.TagMap `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
SnapshotTags map[string]string `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
||||||
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
||||||
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
||||||
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
||||||
|
@ -69,7 +69,7 @@ type FlatConfig struct {
|
||||||
RootVolumeType *string `mapstructure:"root_volume_type" required:"false" cty:"root_volume_type"`
|
RootVolumeType *string `mapstructure:"root_volume_type" required:"false" cty:"root_volume_type"`
|
||||||
SourceAmi *string `mapstructure:"source_ami" required:"true" cty:"source_ami"`
|
SourceAmi *string `mapstructure:"source_ami" required:"true" cty:"source_ami"`
|
||||||
SourceAmiFilter *common.FlatAmiFilterOptions `mapstructure:"source_ami_filter" required:"false" cty:"source_ami_filter"`
|
SourceAmiFilter *common.FlatAmiFilterOptions `mapstructure:"source_ami_filter" required:"false" cty:"source_ami_filter"`
|
||||||
RootVolumeTags common.TagMap `mapstructure:"root_volume_tags" required:"false" cty:"root_volume_tags"`
|
RootVolumeTags map[string]string `mapstructure:"root_volume_tags" required:"false" cty:"root_volume_tags"`
|
||||||
RootVolumeTag []hcl2template.FlatKeyValue `mapstructure:"root_volume_tag" required:"false" cty:"root_volume_tag"`
|
RootVolumeTag []hcl2template.FlatKeyValue `mapstructure:"root_volume_tag" required:"false" cty:"root_volume_tag"`
|
||||||
Architecture *string `mapstructure:"ami_architecture" required:"false" cty:"ami_architecture"`
|
Architecture *string `mapstructure:"ami_architecture" required:"false" cty:"ami_architecture"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ type StepCreateVolume struct {
|
||||||
volumeId string
|
volumeId string
|
||||||
RootVolumeSize int64
|
RootVolumeSize int64
|
||||||
RootVolumeType string
|
RootVolumeType string
|
||||||
RootVolumeTags awscommon.TagMap
|
RootVolumeTags map[string]string
|
||||||
Ctx interpolate.Context
|
Ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func (s *StepCreateVolume) Run(ctx context.Context, state multistep.StateBag) mu
|
||||||
instance := state.Get("instance").(*ec2.Instance)
|
instance := state.Get("instance").(*ec2.Instance)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
volTags, err := s.RootVolumeTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
volTags, err := awscommon.TagMap(s.RootVolumeTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error tagging volumes: %s", err)
|
err := fmt.Errorf("Error tagging volumes: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -50,7 +50,7 @@ type AMIConfig struct {
|
||||||
// Tags applied to the AMI. This is a
|
// Tags applied to the AMI. This is a
|
||||||
// [template engine](/docs/templates/engine.html), see [Build template
|
// [template engine](/docs/templates/engine.html), see [Build template
|
||||||
// data](#build-template-data) for more information.
|
// data](#build-template-data) for more information.
|
||||||
AMITags TagMap `mapstructure:"tags" required:"false"`
|
AMITags map[string]string `mapstructure:"tags" required:"false"`
|
||||||
// Same as [`tags`](#tags) but defined as a singular repeatable block
|
// Same as [`tags`](#tags) but defined as a singular repeatable block
|
||||||
// containing a key and a value field. In HCL2 mode the
|
// containing a key and a value field. In HCL2 mode the
|
||||||
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
||||||
|
@ -121,7 +121,7 @@ type AMIConfig struct {
|
||||||
// They will override AMI tags if already applied to snapshot. This is a
|
// They will override AMI tags if already applied to snapshot. This is a
|
||||||
// [template engine](../templates/engine.html), see [Build template
|
// [template engine](../templates/engine.html), see [Build template
|
||||||
// data](#build-template-data) for more information.
|
// data](#build-template-data) for more information.
|
||||||
SnapshotTags TagMap `mapstructure:"snapshot_tags" required:"false"`
|
SnapshotTags map[string]string `mapstructure:"snapshot_tags" required:"false"`
|
||||||
// Same as [`snapshot_tags`](#snapshot_tags) but defined as a singular
|
// Same as [`snapshot_tags`](#snapshot_tags) but defined as a singular
|
||||||
// repeatable block containing a key and a value field. In HCL2 mode the
|
// repeatable block containing a key and a value field. In HCL2 mode the
|
||||||
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
||||||
|
|
|
@ -423,15 +423,8 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
||||||
errs := c.Comm.Prepare(ctx)
|
errs := c.Comm.Prepare(ctx)
|
||||||
|
|
||||||
// Copy singular tag maps
|
// Copy singular tag maps
|
||||||
for _, s := range []struct {
|
errs = append(errs, c.RunTag.CopyOn(&c.RunTags)...)
|
||||||
tagMap TagMap
|
errs = append(errs, c.SpotTag.CopyOn(&c.SpotTags)...)
|
||||||
kvs hcl2template.KeyValues
|
|
||||||
}{
|
|
||||||
{c.RunTags, c.RunTag},
|
|
||||||
{c.SpotTags, c.SpotTag},
|
|
||||||
} {
|
|
||||||
errs = append(errs, s.kvs.CopyOn(&s.tagMap)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, preparer := range []interface{ Prepare() []error }{
|
for _, preparer := range []interface{ Prepare() []error }{
|
||||||
&c.SourceAmiFilter,
|
&c.SourceAmiFilter,
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type StepCreateTags struct {
|
type StepCreateTags struct {
|
||||||
Tags TagMap
|
Tags map[string]string
|
||||||
SnapshotTags TagMap
|
SnapshotTags map[string]string
|
||||||
Ctx interpolate.Context
|
Ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ func (s *StepCreateTags) Run(ctx context.Context, state multistep.StateBag) mult
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
amis := state.Get("amis").(map[string]string)
|
amis := state.Get("amis").(map[string]string)
|
||||||
|
|
||||||
if !s.Tags.IsSet() && !s.SnapshotTags.IsSet() {
|
if len(s.Tags) == 0 && len(s.SnapshotTags) == 0 {
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ func (s *StepCreateTags) Run(ctx context.Context, state multistep.StateBag) mult
|
||||||
|
|
||||||
// Convert tags to ec2.Tag format
|
// Convert tags to ec2.Tag format
|
||||||
ui.Say("Creating AMI tags")
|
ui.Say("Creating AMI tags")
|
||||||
amiTags, err := s.Tags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
amiTags, err := TagMap(s.Tags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -81,7 +81,7 @@ func (s *StepCreateTags) Run(ctx context.Context, state multistep.StateBag) mult
|
||||||
amiTags.Report(ui)
|
amiTags.Report(ui)
|
||||||
|
|
||||||
ui.Say("Creating snapshot tags")
|
ui.Say("Creating snapshot tags")
|
||||||
snapshotTags, err := s.SnapshotTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
snapshotTags, err := TagMap(s.SnapshotTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
|
|
@ -31,10 +31,10 @@ type StepRunSourceInstance struct {
|
||||||
InstanceType string
|
InstanceType string
|
||||||
IsRestricted bool
|
IsRestricted bool
|
||||||
SourceAMI string
|
SourceAMI string
|
||||||
Tags TagMap
|
Tags map[string]string
|
||||||
UserData string
|
UserData string
|
||||||
UserDataFile string
|
UserDataFile string
|
||||||
VolumeTags TagMap
|
VolumeTags map[string]string
|
||||||
NoEphemeral bool
|
NoEphemeral bool
|
||||||
|
|
||||||
instanceId string
|
instanceId string
|
||||||
|
@ -88,7 +88,7 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
|
||||||
s.Tags["Name"] = "Packer Builder"
|
s.Tags["Name"] = "Packer Builder"
|
||||||
}
|
}
|
||||||
|
|
||||||
ec2Tags, err := s.Tags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
ec2Tags, err := TagMap(s.Tags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error tagging source instance: %s", err)
|
err := fmt.Errorf("Error tagging source instance: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -96,7 +96,7 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
volTags, err := s.VolumeTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
volTags, err := TagMap(s.VolumeTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error tagging volumes: %s", err)
|
err := fmt.Errorf("Error tagging volumes: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -322,10 +322,10 @@ func (s *StepRunSourceInstance) Run(ctx context.Context, state multistep.StateBa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(volumeIds) > 0 && s.VolumeTags.IsSet() {
|
if len(volumeIds) > 0 && len(s.VolumeTags) > 0 {
|
||||||
ui.Say("Adding tags to source EBS Volumes")
|
ui.Say("Adding tags to source EBS Volumes")
|
||||||
|
|
||||||
volumeTags, err := s.VolumeTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
volumeTags, err := TagMap(s.VolumeTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err)
|
err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -34,10 +34,10 @@ type StepRunSpotInstance struct {
|
||||||
InstanceType string
|
InstanceType string
|
||||||
SourceAMI string
|
SourceAMI string
|
||||||
SpotPrice string
|
SpotPrice string
|
||||||
SpotTags TagMap
|
SpotTags map[string]string
|
||||||
SpotInstanceTypes []string
|
SpotInstanceTypes []string
|
||||||
Tags TagMap
|
Tags map[string]string
|
||||||
VolumeTags TagMap
|
VolumeTags map[string]string
|
||||||
UserData string
|
UserData string
|
||||||
UserDataFile string
|
UserDataFile string
|
||||||
Ctx interpolate.Context
|
Ctx interpolate.Context
|
||||||
|
@ -194,7 +194,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert tags from the tag map provided by the user into *ec2.Tag s
|
// Convert tags from the tag map provided by the user into *ec2.Tag s
|
||||||
ec2Tags, err := s.Tags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
ec2Tags, err := TagMap(s.Tags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error generating tags for source instance: %s", err)
|
err := fmt.Errorf("Error generating tags for source instance: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -336,7 +336,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
|
||||||
instance := describeOutput.Reservations[0].Instances[0]
|
instance := describeOutput.Reservations[0].Instances[0]
|
||||||
|
|
||||||
// Tag the spot instance request (not the eventual spot instance)
|
// Tag the spot instance request (not the eventual spot instance)
|
||||||
spotTags, err := s.SpotTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
spotTags, err := TagMap(s.SpotTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error generating tags for spot request: %s", err)
|
err := fmt.Errorf("Error generating tags for spot request: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -344,7 +344,7 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(spotTags) > 0 && s.SpotTags.IsSet() {
|
if len(spotTags) > 0 && len(s.SpotTags) > 0 {
|
||||||
spotTags.Report(ui)
|
spotTags.Report(ui)
|
||||||
// Use the instance ID to find out the SIR, so that we can tag the spot
|
// Use the instance ID to find out the SIR, so that we can tag the spot
|
||||||
// request associated with this instance.
|
// request associated with this instance.
|
||||||
|
@ -400,10 +400,10 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(volumeIds) > 0 && s.VolumeTags.IsSet() {
|
if len(volumeIds) > 0 && len(s.VolumeTags) > 0 {
|
||||||
ui.Say("Adding tags to source EBS Volumes")
|
ui.Say("Adding tags to source EBS Volumes")
|
||||||
|
|
||||||
volumeTags, err := s.VolumeTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
volumeTags, err := TagMap(s.VolumeTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err)
|
err := fmt.Errorf("Error tagging source EBS Volumes on %s: %s", *instance.InstanceId, err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -21,10 +21,6 @@ func (t EC2Tags) Report(ui packer.Ui) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TagMap) IsSet() bool {
|
|
||||||
return len(t) > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t TagMap) EC2Tags(ictx interpolate.Context, region string, state multistep.StateBag) (EC2Tags, error) {
|
func (t TagMap) EC2Tags(ictx interpolate.Context, region string, state multistep.StateBag) (EC2Tags, error) {
|
||||||
var ec2Tags []*ec2.Tag
|
var ec2Tags []*ec2.Tag
|
||||||
generatedData := builder.GeneratedData{State: state}
|
generatedData := builder.GeneratedData{State: state}
|
||||||
|
|
|
@ -38,7 +38,7 @@ type FlatConfig struct {
|
||||||
AMIGroups []string `mapstructure:"ami_groups" required:"false" cty:"ami_groups"`
|
AMIGroups []string `mapstructure:"ami_groups" required:"false" cty:"ami_groups"`
|
||||||
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
||||||
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
||||||
AMITags common.TagMap `mapstructure:"tags" required:"false" cty:"tags"`
|
AMITags map[string]string `mapstructure:"tags" required:"false" cty:"tags"`
|
||||||
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
||||||
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
||||||
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
||||||
|
@ -48,7 +48,7 @@ type FlatConfig struct {
|
||||||
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
||||||
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
||||||
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
||||||
SnapshotTags common.TagMap `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
SnapshotTags map[string]string `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
||||||
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
||||||
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
||||||
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
||||||
|
|
|
@ -153,7 +153,7 @@ type FlatConfig struct {
|
||||||
AMIGroups []string `mapstructure:"ami_groups" required:"false" cty:"ami_groups"`
|
AMIGroups []string `mapstructure:"ami_groups" required:"false" cty:"ami_groups"`
|
||||||
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
||||||
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
||||||
AMITags common.TagMap `mapstructure:"tags" required:"false" cty:"tags"`
|
AMITags map[string]string `mapstructure:"tags" required:"false" cty:"tags"`
|
||||||
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
||||||
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
||||||
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
||||||
|
@ -163,7 +163,7 @@ type FlatConfig struct {
|
||||||
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
||||||
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
||||||
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
||||||
SnapshotTags common.TagMap `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
SnapshotTags map[string]string `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
||||||
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
||||||
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
||||||
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
||||||
|
|
|
@ -14,7 +14,7 @@ type BlockDevice struct {
|
||||||
// Tags to apply to the volume. These are retained after the builder
|
// Tags to apply to the volume. These are retained after the builder
|
||||||
// completes. This is a [template engine](/docs/templates/engine.html), see
|
// completes. This is a [template engine](/docs/templates/engine.html), see
|
||||||
// [Build template data](#build-template-data) for more information.
|
// [Build template data](#build-template-data) for more information.
|
||||||
Tags awscommon.TagMap `mapstructure:"tags" required:"false"`
|
Tags map[string]string `mapstructure:"tags" required:"false"`
|
||||||
// Same as [`tags`](#tags) but defined as a singular repeatable block
|
// Same as [`tags`](#tags) but defined as a singular repeatable block
|
||||||
// containing a key and a value field. In HCL2 mode the
|
// containing a key and a value field. In HCL2 mode the
|
||||||
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
// [`dynamic_block`](https://packer.io/docs/configuration/from-1.5/expressions.html#dynamic-blocks)
|
||||||
|
|
|
@ -64,7 +64,7 @@ type Config struct {
|
||||||
// created. Packer will replace all tags on the volume with the tags
|
// created. Packer will replace all tags on the volume with the tags
|
||||||
// configured in the `ebs_volumes` section as soon as the instance is
|
// configured in the `ebs_volumes` section as soon as the instance is
|
||||||
// reported as 'ready'.
|
// reported as 'ready'.
|
||||||
VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"`
|
VolumeRunTags map[string]string `mapstructure:"run_volume_tags"`
|
||||||
|
|
||||||
launchBlockDevices BlockDevices
|
launchBlockDevices BlockDevices
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ type FlatBlockDevice struct {
|
||||||
VolumeType *string `mapstructure:"volume_type" required:"false" cty:"volume_type"`
|
VolumeType *string `mapstructure:"volume_type" required:"false" cty:"volume_type"`
|
||||||
VolumeSize *int64 `mapstructure:"volume_size" required:"false" cty:"volume_size"`
|
VolumeSize *int64 `mapstructure:"volume_size" required:"false" cty:"volume_size"`
|
||||||
KmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
KmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
||||||
Tags common.TagMap `mapstructure:"tags" required:"false" cty:"tags"`
|
Tags map[string]string `mapstructure:"tags" required:"false" cty:"tags"`
|
||||||
Tag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
Tag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ type FlatConfig struct {
|
||||||
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
||||||
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
||||||
VolumeMappings []FlatBlockDevice `mapstructure:"ebs_volumes" required:"false" cty:"ebs_volumes"`
|
VolumeMappings []FlatBlockDevice `mapstructure:"ebs_volumes" required:"false" cty:"ebs_volumes"`
|
||||||
VolumeRunTags common.TagMap `mapstructure:"run_volume_tags" cty:"run_volume_tags"`
|
VolumeRunTags map[string]string `mapstructure:"run_volume_tags" cty:"run_volume_tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlatMapstructure returns a new FlatConfig.
|
// FlatMapstructure returns a new FlatConfig.
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
awscommon "github.com/hashicorp/packer/builder/amazon/common"
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/template/interpolate"
|
"github.com/hashicorp/packer/template/interpolate"
|
||||||
|
@ -43,11 +44,11 @@ func (s *stepTagEBSVolumes) Run(ctx context.Context, state multistep.StateBag) m
|
||||||
// volume will have had these tags applied when the instance was
|
// volume will have had these tags applied when the instance was
|
||||||
// created. We now need to remove these tags to ensure only the EBS
|
// created. We now need to remove these tags to ensure only the EBS
|
||||||
// volume tags are applied (if any)
|
// volume tags are applied (if any)
|
||||||
if config.VolumeRunTags.IsSet() {
|
if len(config.VolumeRunTags) > 0 {
|
||||||
ui.Say("Removing any tags applied to EBS volumes when the source instance was created...")
|
ui.Say("Removing any tags applied to EBS volumes when the source instance was created...")
|
||||||
|
|
||||||
ui.Message("Compiling list of existing tags to remove...")
|
ui.Message("Compiling list of existing tags to remove...")
|
||||||
existingTags, err := config.VolumeRunTags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
existingTags, err := awscommon.TagMap(config.VolumeRunTags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error generating list of tags to remove: %s", err)
|
err := fmt.Errorf("Error generating list of tags to remove: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
@ -91,7 +92,7 @@ func (s *stepTagEBSVolumes) Run(ctx context.Context, state multistep.StateBag) m
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Message(fmt.Sprintf("Compiling list of tags to apply to volume on %s...", mapping.DeviceName))
|
ui.Message(fmt.Sprintf("Compiling list of tags to apply to volume on %s...", mapping.DeviceName))
|
||||||
tags, err := mapping.Tags.EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
tags, err := awscommon.TagMap(mapping.Tags).EC2Tags(s.Ctx, *ec2conn.Config.Region, state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error generating tags for device %s: %s", mapping.DeviceName, err)
|
err := fmt.Errorf("Error generating tags for device %s: %s", mapping.DeviceName, err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -38,7 +38,7 @@ type FlatConfig struct {
|
||||||
AMIGroups []string `mapstructure:"ami_groups" required:"false" cty:"ami_groups"`
|
AMIGroups []string `mapstructure:"ami_groups" required:"false" cty:"ami_groups"`
|
||||||
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
AMIProductCodes []string `mapstructure:"ami_product_codes" required:"false" cty:"ami_product_codes"`
|
||||||
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
AMIRegions []string `mapstructure:"ami_regions" required:"false" cty:"ami_regions"`
|
||||||
AMITags common.TagMap `mapstructure:"tags" required:"false" cty:"tags"`
|
AMITags map[string]string `mapstructure:"tags" required:"false" cty:"tags"`
|
||||||
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
AMITag []hcl2template.FlatKeyValue `mapstructure:"tag" required:"false" cty:"tag"`
|
||||||
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
AMIENASupport *bool `mapstructure:"ena_support" required:"false" cty:"ena_support"`
|
||||||
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
AMISriovNetSupport *bool `mapstructure:"sriov_support" required:"false" cty:"sriov_support"`
|
||||||
|
@ -48,7 +48,7 @@ type FlatConfig struct {
|
||||||
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
AMIKmsKeyId *string `mapstructure:"kms_key_id" required:"false" cty:"kms_key_id"`
|
||||||
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
AMIRegionKMSKeyIDs map[string]string `mapstructure:"region_kms_key_ids" required:"false" cty:"region_kms_key_ids"`
|
||||||
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
AMISkipBuildRegion *bool `mapstructure:"skip_save_build_region" cty:"skip_save_build_region"`
|
||||||
SnapshotTags common.TagMap `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
SnapshotTags map[string]string `mapstructure:"snapshot_tags" required:"false" cty:"snapshot_tags"`
|
||||||
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
SnapshotTag []hcl2template.FlatKeyValue `mapstructure:"snapshot_tag" required:"false" cty:"snapshot_tag"`
|
||||||
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
SnapshotUsers []string `mapstructure:"snapshot_users" required:"false" cty:"snapshot_users"`
|
||||||
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
SnapshotGroups []string `mapstructure:"snapshot_groups" required:"false" cty:"snapshot_groups"`
|
||||||
|
|
|
@ -121,7 +121,7 @@
|
||||||
criteria provided in `source_ami_filter`; this pins the AMI returned by the
|
criteria provided in `source_ami_filter`; this pins the AMI returned by the
|
||||||
filter, but will cause Packer to fail if the `source_ami` does not exist.
|
filter, but will cause Packer to fail if the `source_ami` does not exist.
|
||||||
|
|
||||||
- `root_volume_tags` (awscommon.TagMap) - Tags to apply to the volumes that are *launched*. This is a [template
|
- `root_volume_tags` (map[string]string) - Tags to apply to the volumes that are *launched*. This is a [template
|
||||||
engine](/docs/templates/engine.html), see [Build template
|
engine](/docs/templates/engine.html), see [Build template
|
||||||
data](#build-template-data) for more information.
|
data](#build-template-data) for more information.
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
- `skip_region_validation` (bool) - Set to true if you want to skip
|
- `skip_region_validation` (bool) - Set to true if you want to skip
|
||||||
validation of the ami_regions configuration option. Default false.
|
validation of the ami_regions configuration option. Default false.
|
||||||
|
|
||||||
- `tags` (TagMap) - Tags applied to the AMI. This is a
|
- `tags` (map[string]string) - Tags applied to the AMI. This is a
|
||||||
[template engine](/docs/templates/engine.html), see [Build template
|
[template engine](/docs/templates/engine.html), see [Build template
|
||||||
data](#build-template-data) for more information.
|
data](#build-template-data) for more information.
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@
|
||||||
the intermediary AMI into any regions provided in `ami_regions`, then
|
the intermediary AMI into any regions provided in `ami_regions`, then
|
||||||
delete the intermediary AMI. Default `false`.
|
delete the intermediary AMI. Default `false`.
|
||||||
|
|
||||||
- `snapshot_tags` (TagMap) - Tags to apply to snapshot.
|
- `snapshot_tags` (map[string]string) - Tags to apply to snapshot.
|
||||||
They will override AMI tags if already applied to snapshot. This is a
|
They will override AMI tags if already applied to snapshot. This is a
|
||||||
[template engine](../templates/engine.html), see [Build template
|
[template engine](../templates/engine.html), see [Build template
|
||||||
data](#build-template-data) for more information.
|
data](#build-template-data) for more information.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<!-- Code generated from the comments of the BlockDevice struct in builder/amazon/ebsvolume/block_device.go; DO NOT EDIT MANUALLY -->
|
<!-- Code generated from the comments of the BlockDevice struct in builder/amazon/ebsvolume/block_device.go; DO NOT EDIT MANUALLY -->
|
||||||
|
|
||||||
- `tags` (awscommon.TagMap) - Tags to apply to the volume. These are retained after the builder
|
- `tags` (map[string]string) - Tags to apply to the volume. These are retained after the builder
|
||||||
completes. This is a [template engine](/docs/templates/engine.html), see
|
completes. This is a [template engine](/docs/templates/engine.html), see
|
||||||
[Build template data](#build-template-data) for more information.
|
[Build template data](#build-template-data) for more information.
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
source instance. See the [BlockDevices](#block-devices-configuration)
|
source instance. See the [BlockDevices](#block-devices-configuration)
|
||||||
documentation for fields.
|
documentation for fields.
|
||||||
|
|
||||||
- `run_volume_tags` (awscommon.TagMap) - Tags to apply to the volumes of the instance that is *launched* to
|
- `run_volume_tags` (map[string]string) - Tags to apply to the volumes of the instance that is *launched* to
|
||||||
create EBS Volumes. These tags will *not* appear in the tags of the
|
create EBS Volumes. These tags will *not* appear in the tags of the
|
||||||
resulting EBS volumes unless they're duplicated under `tags` in the
|
resulting EBS volumes unless they're duplicated under `tags` in the
|
||||||
`ebs_volumes` setting. This is a [template
|
`ebs_volumes` setting. This is a [template
|
||||||
|
|
Loading…
Reference in New Issue