allow user to set architecture

This commit is contained in:
Megan Marsh 2019-05-07 16:38:55 -07:00
parent d2bb42a9ba
commit 02c9f24531
6 changed files with 43 additions and 4 deletions

View File

@ -46,6 +46,7 @@ type Config struct {
SourceAmi string `mapstructure:"source_ami"`
SourceAmiFilter awscommon.AmiFilterOptions `mapstructure:"source_ami_filter"`
RootVolumeTags awscommon.TagMap `mapstructure:"root_volume_tags"`
Architecture string `mapstructure:"ami_architecture"`
ctx interpolate.Context
}
@ -81,6 +82,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, err
}
if b.config.Architecture == "" {
b.config.Architecture == "x86_64"
}
if b.config.PackerConfig.PackerForce {
b.config.AMIForceDeregister = true
}
@ -180,6 +185,16 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs, errors.New("If root_device_name is specified, ami_block_device_mappings must be specified"))
}
}
valid := false
for validArch, _ := range []string{"x86_64", "arm64"} {
if validArch == b.config.Architecture {
matched = true
break
}
}
if !valid {
errs = packer.MultiErrorAppend(errs, errors.New(`The only valid ami_architecture values are "x86_64" and "arm64"`))
}
if errs != nil && len(errs.Errors) > 0 {
return warns, errs
@ -276,6 +291,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
RootVolumeSize: b.config.RootVolumeSize,
EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
EnableAMIENASupport: b.config.AMIENASupport,
Architecture: b.config.Architecture,
},
&awscommon.StepAMIRegionCopy{
AccessConfig: &b.config.AccessConfig,

View File

@ -16,6 +16,7 @@ type StepRegisterAMI struct {
RootVolumeSize int64
EnableAMIENASupport *bool
EnableAMISriovNetSupport bool
Architecture string
}
func (s *StepRegisterAMI) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
@ -117,7 +118,7 @@ func buildBaseRegisterOpts(config *Config, sourceImage *ec2.Image, rootVolumeSiz
if config.FromScratch {
return &ec2.RegisterImageInput{
Name: &config.AMIName,
Architecture: aws.String(ec2.ArchitectureValuesX8664),
Architecture: aws.String(s.Architecture),
RootDeviceName: aws.String(rootDeviceName),
VirtualizationType: aws.String(config.AMIVirtType),
BlockDeviceMappings: newMappings,

View File

@ -28,6 +28,7 @@ type Config struct {
RootDevice RootBlockDevice `mapstructure:"ami_root_device"`
VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"`
Architecture string `mapstructure:"ami_architecture"`
ctx interpolate.Context
}
@ -92,6 +93,19 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"you use an AMI that already has either SR-IOV or ENA enabled."))
}
if b.config.Architecture == "" {
b.config.Architecture == "x86_64"
}
valid := false
for validArch, _ := range []string{"x86_64", "arm64"} {
if validArch == b.config.Architecture {
matched = true
break
}
}
if !valid {
errs = packer.MultiErrorAppend(errs, errors.New(`The only valid ami_architecture values are "x86_64" and "arm64"`))
}
if errs != nil && len(errs.Errors) > 0 {
return nil, errs
}
@ -244,6 +258,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
LaunchDevices: launchDevices,
EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
EnableAMIENASupport: b.config.AMIENASupport,
Architecture: b.config.Architecture,
},
&awscommon.StepAMIRegionCopy{
AccessConfig: &b.config.AccessConfig,

View File

@ -18,6 +18,7 @@ type StepRegisterAMI struct {
LaunchDevices []*ec2.BlockDeviceMapping
EnableAMIENASupport *bool
EnableAMISriovNetSupport bool
Architecture string
image *ec2.Image
}
@ -33,7 +34,7 @@ func (s *StepRegisterAMI) Run(ctx context.Context, state multistep.StateBag) mul
registerOpts := &ec2.RegisterImageInput{
Name: &config.AMIName,
Architecture: aws.String(ec2.ArchitectureValuesX8664),
Architecture: aws.String(s.Architecture),
RootDeviceName: aws.String(s.RootDevice.DeviceName),
VirtualizationType: aws.String(config.AMIVirtType),
BlockDeviceMappings: blockDevices,

View File

@ -75,6 +75,9 @@ each category, the available configuration keys are alphabetized.
### Optional:
- `ami_architecture` (string) - what architecture to use when registering the
final AMI; valid options are "x86_64" or "arm64". Defaults to "x86_64".
- `ami_description` (string) - The description to set for the resulting
AMI(s). By default this description is empty. This is a [template
engine](/docs/templates/engine.html), see [Build template
@ -141,8 +144,8 @@ each category, the available configuration keys are alphabetized.
documentation on enabling enhanced
networking](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking.html#enabling_enhanced_networking).
- `encrypt_boot` (boolean) - Whether or not to encrypt the resulting AMI when
copying a provisioned instance to an AMI. By default, Packer will keep the
- `encrypt_boot` (boolean) - Whether or not to encrypt the resulting AMI when
copying a provisioned instance to an AMI. By default, Packer will keep the
encryption setting to what it was in the source image. Setting `false` will
result in an unencrypted image, and `true` will result in an encrypted one.

View File

@ -61,6 +61,9 @@ builder.
### Optional:
- `ami_architecture` (string) - what architecture to use when registering the
final AMI; valid options are "x86_64" or "arm64". Defaults to "x86_64".
- `ami_block_device_mappings` (array of block device mappings) - Add one or
more [block device
mappings](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html)