2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
2019-12-17 05:25:56 -05:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config,RootBlockDevice,BlockDevice
|
2019-05-31 08:27:41 -04:00
|
|
|
|
2016-12-30 16:21:23 -05:00
|
|
|
// The ebssurrogate package contains a packer.Builder implementation that
|
|
|
|
// builds a new EBS-backed AMI using an ephemeral instance.
|
|
|
|
package ebssurrogate
|
|
|
|
|
|
|
|
import (
|
2019-03-22 09:53:28 -04:00
|
|
|
"context"
|
2016-12-30 16:21:23 -05:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2020-02-14 11:42:29 -05:00
|
|
|
|
2016-12-30 16:21:23 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2019-10-31 06:31:17 -04:00
|
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
2019-12-17 05:25:56 -05:00
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
2020-01-20 10:29:38 -05:00
|
|
|
"github.com/hashicorp/packer/builder"
|
2017-04-04 16:39:01 -04:00
|
|
|
awscommon "github.com/hashicorp/packer/builder/amazon/common"
|
|
|
|
"github.com/hashicorp/packer/common"
|
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/helper/config"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2016-12-30 16:21:23 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const BuilderId = "mitchellh.amazon.ebssurrogate"
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
common.PackerConfig `mapstructure:",squash"`
|
|
|
|
awscommon.AccessConfig `mapstructure:",squash"`
|
|
|
|
awscommon.RunConfig `mapstructure:",squash"`
|
|
|
|
awscommon.AMIConfig `mapstructure:",squash"`
|
2019-06-18 12:00:49 -04:00
|
|
|
|
|
|
|
// Add one or more block device mappings to the AMI. These will be attached
|
|
|
|
// when booting a new instance from your AMI. To add a block device during
|
|
|
|
// the Packer build see `launch_block_device_mappings` below. Your options
|
|
|
|
// here may vary depending on the type of VM you use. See the
|
|
|
|
// [BlockDevices](#block-devices-configuration) documentation for fields.
|
|
|
|
AMIMappings awscommon.BlockDevices `mapstructure:"ami_block_device_mappings" required:"false"`
|
|
|
|
// Add one or more block devices before the Packer build starts. If you add
|
|
|
|
// instance store volumes or EBS volumes in addition to the root device
|
|
|
|
// volume, the created AMI will contain block device mapping information
|
|
|
|
// for those volumes. Amazon creates snapshots of the source instance's
|
|
|
|
// root volume and any other EBS volumes described here. When you launch an
|
|
|
|
// instance from this new AMI, the instance automatically launches with
|
|
|
|
// these additional volumes, and will restore them from snapshots taken
|
|
|
|
// from the source instance. See the
|
|
|
|
// [BlockDevices](#block-devices-configuration) documentation for fields.
|
|
|
|
LaunchMappings BlockDevices `mapstructure:"launch_block_device_mappings" required:"false"`
|
2019-06-06 10:45:37 -04:00
|
|
|
// A block device mapping describing the root device of the AMI. This looks
|
|
|
|
// like the mappings in `ami_block_device_mapping`, except with an
|
|
|
|
// additional field:
|
|
|
|
//
|
|
|
|
// - `source_device_name` (string) - The device name of the block device on
|
|
|
|
// the source instance to be used as the root device for the AMI. This
|
|
|
|
// must correspond to a block device in `launch_block_device_mapping`.
|
|
|
|
RootDevice RootBlockDevice `mapstructure:"ami_root_device" required:"true"`
|
|
|
|
// 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
|
2020-04-01 18:54:21 -04:00
|
|
|
// engine](/docs/templates/engine), see [Build template
|
2019-06-06 10:45:37 -04:00
|
|
|
// data](#build-template-data) for more information.
|
2018-02-02 23:16:23 -05:00
|
|
|
VolumeRunTags awscommon.TagMap `mapstructure:"run_volume_tags"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// what architecture to use when registering the
|
2019-06-06 10:29:25 -04:00
|
|
|
// final AMI; valid options are "x86_64" or "arm64". Defaults to "x86_64".
|
|
|
|
Architecture string `mapstructure:"ami_architecture" required:"false"`
|
2016-12-30 16:21:23 -05:00
|
|
|
|
|
|
|
ctx interpolate.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type Builder struct {
|
|
|
|
config Config
|
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
2019-12-17 05:25:56 -05:00
|
|
|
func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
|
|
|
|
|
2019-12-17 00:23:05 -05:00
|
|
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
2016-12-30 16:21:23 -05:00
|
|
|
b.config.ctx.Funcs = awscommon.TemplateFuncs
|
|
|
|
err := config.Decode(&b.config, &config.DecodeOpts{
|
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &b.config.ctx,
|
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"ami_description",
|
|
|
|
"run_tags",
|
2017-02-27 08:51:38 -05:00
|
|
|
"run_volume_tags",
|
|
|
|
"snapshot_tags",
|
2017-10-12 17:33:01 -04:00
|
|
|
"spot_tags",
|
2016-12-30 16:21:23 -05:00
|
|
|
"tags",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, raws...)
|
|
|
|
if err != nil {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, nil, err
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
|
2017-03-09 17:24:49 -05:00
|
|
|
if b.config.PackerConfig.PackerForce {
|
|
|
|
b.config.AMIForceDeregister = true
|
|
|
|
}
|
|
|
|
|
2016-12-30 16:21:23 -05:00
|
|
|
// Accumulate any errors
|
|
|
|
var errs *packer.MultiError
|
2019-06-28 17:00:56 -04:00
|
|
|
var warns []string
|
2016-12-30 16:21:23 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(&b.config.ctx)...)
|
2017-10-30 17:17:19 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs,
|
|
|
|
b.config.AMIConfig.Prepare(&b.config.AccessConfig, &b.config.ctx)...)
|
2019-06-18 06:37:47 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.AMIMappings.Prepare(&b.config.ctx)...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.LaunchMappings.Prepare(&b.config.ctx)...)
|
2016-12-30 16:21:23 -05:00
|
|
|
errs = packer.MultiErrorAppend(errs, b.config.RootDevice.Prepare(&b.config.ctx)...)
|
|
|
|
|
|
|
|
if b.config.AMIVirtType == "" {
|
|
|
|
errs = packer.MultiErrorAppend(errs, errors.New("ami_virtualization_type is required."))
|
|
|
|
}
|
|
|
|
|
|
|
|
foundRootVolume := false
|
2019-06-18 06:37:47 -04:00
|
|
|
for _, launchDevice := range b.config.LaunchMappings {
|
2016-12-30 16:21:23 -05:00
|
|
|
if launchDevice.DeviceName == b.config.RootDevice.SourceDeviceName {
|
|
|
|
foundRootVolume = true
|
2019-05-03 12:39:52 -04:00
|
|
|
if launchDevice.OmitFromArtifact {
|
|
|
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("You cannot set \"omit_from_artifact\": \"true\" for the root volume."))
|
|
|
|
}
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !foundRootVolume {
|
|
|
|
errs = packer.MultiErrorAppend(errs, fmt.Errorf("no volume with name '%s' is found", b.config.RootDevice.SourceDeviceName))
|
|
|
|
}
|
|
|
|
|
2019-06-28 17:00:56 -04:00
|
|
|
if b.config.RunConfig.SpotPriceAutoProduct != "" {
|
|
|
|
warns = append(warns, "spot_price_auto_product is deprecated and no "+
|
|
|
|
"longer necessary for Packer builds. In future versions of "+
|
|
|
|
"Packer, inclusion of spot_price_auto_product will error your "+
|
|
|
|
"builds. Please take a look at our current documentation to "+
|
|
|
|
"understand how Packer requests Spot instances.")
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:38:55 -04:00
|
|
|
if b.config.Architecture == "" {
|
2019-05-07 19:44:29 -04:00
|
|
|
b.config.Architecture = "x86_64"
|
2019-05-07 19:38:55 -04:00
|
|
|
}
|
|
|
|
valid := false
|
2019-05-07 19:44:29 -04:00
|
|
|
for _, validArch := range []string{"x86_64", "arm64"} {
|
2019-05-07 19:38:55 -04:00
|
|
|
if validArch == b.config.Architecture {
|
2019-05-07 19:44:29 -04:00
|
|
|
valid = true
|
2019-05-07 19:38:55 -04:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !valid {
|
|
|
|
errs = packer.MultiErrorAppend(errs, errors.New(`The only valid ami_architecture values are "x86_64" and "arm64"`))
|
|
|
|
}
|
2016-12-30 16:21:23 -05:00
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
2019-12-17 00:23:05 -05:00
|
|
|
return nil, warns, errs
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:25:14 -04:00
|
|
|
packer.LogSecretFilter.Set(b.config.AccessKey, b.config.SecretKey, b.config.Token)
|
2019-06-28 17:00:56 -04:00
|
|
|
|
2020-01-16 06:04:03 -05:00
|
|
|
generatedData := []string{"SourceAMIName"}
|
|
|
|
return generatedData, warns, nil
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
|
2019-03-22 09:53:28 -04:00
|
|
|
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
2017-03-01 19:43:09 -05:00
|
|
|
session, err := b.config.Session()
|
2016-12-30 16:21:23 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-22 06:40:18 -04:00
|
|
|
|
2019-03-04 19:22:52 -05:00
|
|
|
ec2conn := ec2.New(session)
|
2019-10-22 06:40:18 -04:00
|
|
|
iam := iam.New(session)
|
2016-12-30 16:21:23 -05:00
|
|
|
|
|
|
|
// Setup the state bag and initial state for the steps
|
|
|
|
state := new(multistep.BasicStateBag)
|
|
|
|
state.Put("config", &b.config)
|
2019-02-05 17:07:04 -05:00
|
|
|
state.Put("access_config", &b.config.AccessConfig)
|
|
|
|
state.Put("ami_config", &b.config.AMIConfig)
|
2016-12-30 16:21:23 -05:00
|
|
|
state.Put("ec2", ec2conn)
|
2019-10-22 06:40:18 -04:00
|
|
|
state.Put("iam", iam)
|
2017-12-19 14:04:17 -05:00
|
|
|
state.Put("awsSession", session)
|
2016-12-30 16:21:23 -05:00
|
|
|
state.Put("hook", hook)
|
|
|
|
state.Put("ui", ui)
|
2020-01-20 10:29:38 -05:00
|
|
|
generatedData := &builder.GeneratedData{State: state}
|
2016-12-30 16:21:23 -05:00
|
|
|
|
2017-10-04 05:29:38 -04:00
|
|
|
var instanceStep multistep.Step
|
|
|
|
|
2017-12-08 17:56:19 -05:00
|
|
|
if b.config.IsSpotInstance() {
|
2017-10-23 15:16:12 -04:00
|
|
|
instanceStep = &awscommon.StepRunSpotInstance{
|
2017-12-08 17:56:19 -05:00
|
|
|
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
|
2019-06-18 06:37:47 -04:00
|
|
|
LaunchMappings: b.config.LaunchMappings,
|
2018-09-03 02:33:58 -04:00
|
|
|
BlockDurationMinutes: b.config.BlockDurationMinutes,
|
2017-12-08 17:56:19 -05:00
|
|
|
Ctx: b.config.ctx,
|
2018-09-11 21:20:14 -04:00
|
|
|
Comm: &b.config.RunConfig.Comm,
|
2017-12-08 17:56:19 -05:00
|
|
|
Debug: b.config.PackerDebug,
|
|
|
|
EbsOptimized: b.config.EbsOptimized,
|
|
|
|
ExpectedRootDevice: "ebs",
|
2017-10-04 05:29:38 -04:00
|
|
|
InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior,
|
2017-12-08 17:56:19 -05:00
|
|
|
InstanceType: b.config.InstanceType,
|
|
|
|
SourceAMI: b.config.SourceAmi,
|
|
|
|
SpotPrice: b.config.SpotPrice,
|
2019-05-22 13:16:42 -04:00
|
|
|
SpotInstanceTypes: b.config.SpotInstanceTypes,
|
2017-10-12 17:33:01 -04:00
|
|
|
SpotTags: b.config.SpotTags,
|
2017-12-08 17:56:19 -05:00
|
|
|
Tags: b.config.RunTags,
|
|
|
|
UserData: b.config.UserData,
|
|
|
|
UserDataFile: b.config.UserDataFile,
|
|
|
|
VolumeTags: b.config.VolumeRunTags,
|
2017-10-04 05:29:38 -04:00
|
|
|
}
|
|
|
|
} else {
|
2017-10-23 15:16:12 -04:00
|
|
|
instanceStep = &awscommon.StepRunSourceInstance{
|
2017-12-08 17:56:19 -05:00
|
|
|
AssociatePublicIpAddress: b.config.AssociatePublicIpAddress,
|
2019-06-18 06:37:47 -04:00
|
|
|
LaunchMappings: b.config.LaunchMappings,
|
2018-08-30 06:50:29 -04:00
|
|
|
Comm: &b.config.RunConfig.Comm,
|
2017-12-08 17:56:19 -05:00
|
|
|
Ctx: b.config.ctx,
|
|
|
|
Debug: b.config.PackerDebug,
|
|
|
|
EbsOptimized: b.config.EbsOptimized,
|
2018-05-13 12:16:10 -04:00
|
|
|
EnableT2Unlimited: b.config.EnableT2Unlimited,
|
2017-12-08 17:56:19 -05:00
|
|
|
ExpectedRootDevice: "ebs",
|
2017-10-04 05:29:38 -04:00
|
|
|
InstanceInitiatedShutdownBehavior: b.config.InstanceInitiatedShutdownBehavior,
|
2017-12-08 17:56:19 -05:00
|
|
|
InstanceType: b.config.InstanceType,
|
2018-02-02 23:16:23 -05:00
|
|
|
IsRestricted: b.config.IsChinaCloud() || b.config.IsGovCloud(),
|
2017-12-08 17:56:19 -05:00
|
|
|
SourceAMI: b.config.SourceAmi,
|
|
|
|
Tags: b.config.RunTags,
|
|
|
|
UserData: b.config.UserData,
|
|
|
|
UserDataFile: b.config.UserDataFile,
|
|
|
|
VolumeTags: b.config.VolumeRunTags,
|
2017-10-04 05:29:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-18 06:44:24 -04:00
|
|
|
amiDevices := b.config.AMIMappings.BuildEC2BlockDeviceMappings()
|
|
|
|
launchDevices := b.config.LaunchMappings.BuildEC2BlockDeviceMappings()
|
2018-03-25 19:25:53 -04:00
|
|
|
|
2016-12-30 16:21:23 -05:00
|
|
|
// Build the steps
|
|
|
|
steps := []multistep.Step{
|
2017-02-27 08:51:38 -05:00
|
|
|
&awscommon.StepPreValidate{
|
|
|
|
DestAmiName: b.config.AMIName,
|
|
|
|
ForceDeregister: b.config.AMIForceDeregister,
|
2019-11-08 16:13:45 -05:00
|
|
|
VpcId: b.config.VpcId,
|
|
|
|
SubnetId: b.config.SubnetId,
|
2020-03-13 12:17:24 -04:00
|
|
|
HasSubnetFilter: !b.config.SubnetFilter.Empty(),
|
2017-02-27 08:51:38 -05:00
|
|
|
},
|
2016-12-30 16:21:23 -05:00
|
|
|
&awscommon.StepSourceAMIInfo{
|
2017-08-28 12:18:23 -04:00
|
|
|
SourceAmi: b.config.SourceAmi,
|
|
|
|
EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
|
|
|
|
EnableAMIENASupport: b.config.AMIENASupport,
|
|
|
|
AmiFilters: b.config.SourceAmiFilter,
|
2018-09-04 21:13:18 -04:00
|
|
|
AMIVirtType: b.config.AMIVirtType,
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
2018-08-14 06:04:13 -04:00
|
|
|
&awscommon.StepNetworkInfo{
|
|
|
|
VpcId: b.config.VpcId,
|
|
|
|
VpcFilter: b.config.VpcFilter,
|
|
|
|
SecurityGroupIds: b.config.SecurityGroupIds,
|
|
|
|
SecurityGroupFilter: b.config.SecurityGroupFilter,
|
|
|
|
SubnetId: b.config.SubnetId,
|
|
|
|
SubnetFilter: b.config.SubnetFilter,
|
|
|
|
AvailabilityZone: b.config.AvailabilityZone,
|
|
|
|
},
|
2016-12-30 16:21:23 -05:00
|
|
|
&awscommon.StepKeyPair{
|
2018-08-28 11:47:02 -04:00
|
|
|
Debug: b.config.PackerDebug,
|
|
|
|
Comm: &b.config.RunConfig.Comm,
|
|
|
|
DebugKeyPath: fmt.Sprintf("ec2_%s.pem", b.config.PackerBuildName),
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
|
|
|
&awscommon.StepSecurityGroup{
|
2019-03-30 18:47:03 -04:00
|
|
|
SecurityGroupFilter: b.config.SecurityGroupFilter,
|
|
|
|
SecurityGroupIds: b.config.SecurityGroupIds,
|
|
|
|
CommConfig: &b.config.RunConfig.Comm,
|
|
|
|
TemporarySGSourceCidrs: b.config.TemporarySGSourceCidrs,
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
2019-10-22 06:40:18 -04:00
|
|
|
&awscommon.StepIamInstanceProfile{
|
|
|
|
IamInstanceProfile: b.config.IamInstanceProfile,
|
2019-12-10 03:17:39 -05:00
|
|
|
SkipProfileValidation: b.config.SkipProfileValidation,
|
2019-10-22 06:40:18 -04:00
|
|
|
TemporaryIamInstanceProfilePolicyDocument: b.config.TemporaryIamInstanceProfilePolicyDocument,
|
|
|
|
},
|
2018-07-26 02:30:51 -04:00
|
|
|
&awscommon.StepCleanupVolumes{
|
2019-06-18 10:02:08 -04:00
|
|
|
LaunchMappings: b.config.LaunchMappings.Common(),
|
2018-07-26 02:30:51 -04:00
|
|
|
},
|
2017-10-04 05:29:38 -04:00
|
|
|
instanceStep,
|
2016-12-30 16:21:23 -05:00
|
|
|
&awscommon.StepGetPassword{
|
2018-04-16 14:51:04 -04:00
|
|
|
Debug: b.config.PackerDebug,
|
|
|
|
Comm: &b.config.RunConfig.Comm,
|
2019-10-31 10:49:34 -04:00
|
|
|
Timeout: b.config.WindowsPasswordTimeout,
|
2018-04-16 14:51:04 -04:00
|
|
|
BuildName: b.config.PackerBuildName,
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
|
|
|
&communicator.StepConnect{
|
|
|
|
Config: &b.config.RunConfig.Comm,
|
|
|
|
Host: awscommon.SSHHost(
|
|
|
|
ec2conn,
|
2019-09-26 15:30:04 -04:00
|
|
|
b.config.SSHInterface,
|
2020-01-30 18:22:22 -05:00
|
|
|
b.config.Comm.Host(),
|
2019-09-26 15:30:04 -04:00
|
|
|
),
|
2018-08-22 11:02:23 -04:00
|
|
|
SSHConfig: b.config.RunConfig.Comm.SSHConfigFunc(),
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
|
|
|
&common.StepProvision{},
|
2018-09-14 14:03:23 -04:00
|
|
|
&common.StepCleanupTempKeys{
|
|
|
|
Comm: &b.config.RunConfig.Comm,
|
|
|
|
},
|
2016-12-30 16:21:23 -05:00
|
|
|
&awscommon.StepStopEBSBackedInstance{
|
2017-12-08 17:56:19 -05:00
|
|
|
Skip: b.config.IsSpotInstance(),
|
2016-12-30 16:21:23 -05:00
|
|
|
DisableStopInstance: b.config.DisableStopInstance,
|
|
|
|
},
|
|
|
|
&awscommon.StepModifyEBSBackedInstance{
|
2019-11-21 05:13:32 -05:00
|
|
|
Skip: b.config.IsSpotInstance(),
|
2017-08-28 12:18:23 -04:00
|
|
|
EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
|
|
|
|
EnableAMIENASupport: b.config.AMIENASupport,
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
2018-03-25 19:25:53 -04:00
|
|
|
&StepSnapshotVolumes{
|
2019-05-03 12:39:52 -04:00
|
|
|
LaunchDevices: launchDevices,
|
2019-06-18 06:37:47 -04:00
|
|
|
SnapshotOmitMap: b.config.LaunchMappings.GetOmissions(),
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
2017-02-27 08:51:38 -05:00
|
|
|
&awscommon.StepDeregisterAMI{
|
2017-08-14 12:20:08 -04:00
|
|
|
AccessConfig: &b.config.AccessConfig,
|
2017-02-27 08:51:38 -05:00
|
|
|
ForceDeregister: b.config.AMIForceDeregister,
|
|
|
|
ForceDeleteSnapshot: b.config.AMIForceDeleteSnapshot,
|
|
|
|
AMIName: b.config.AMIName,
|
2017-08-14 12:20:08 -04:00
|
|
|
Regions: b.config.AMIRegions,
|
2017-02-27 08:51:38 -05:00
|
|
|
},
|
2016-12-30 16:21:23 -05:00
|
|
|
&StepRegisterAMI{
|
2017-08-28 12:18:23 -04:00
|
|
|
RootDevice: b.config.RootDevice,
|
2018-03-25 19:25:53 -04:00
|
|
|
AMIDevices: amiDevices,
|
|
|
|
LaunchDevices: launchDevices,
|
2017-08-28 12:18:23 -04:00
|
|
|
EnableAMISriovNetSupport: b.config.AMISriovNetSupport,
|
|
|
|
EnableAMIENASupport: b.config.AMIENASupport,
|
2019-05-07 19:38:55 -04:00
|
|
|
Architecture: b.config.Architecture,
|
2019-06-18 06:37:47 -04:00
|
|
|
LaunchOmitMap: b.config.LaunchMappings.GetOmissions(),
|
2019-10-09 19:02:37 -04:00
|
|
|
AMISkipBuildRegion: b.config.AMISkipBuildRegion,
|
2016-12-30 16:21:23 -05:00
|
|
|
},
|
2017-02-27 08:51:38 -05:00
|
|
|
&awscommon.StepAMIRegionCopy{
|
2017-06-01 12:28:17 -04:00
|
|
|
AccessConfig: &b.config.AccessConfig,
|
|
|
|
Regions: b.config.AMIRegions,
|
2019-04-15 19:44:56 -04:00
|
|
|
AMIKmsKeyId: b.config.AMIKmsKeyId,
|
2017-06-01 12:28:17 -04:00
|
|
|
RegionKeyIds: b.config.AMIRegionKMSKeyIDs,
|
|
|
|
EncryptBootVolume: b.config.AMIEncryptBootVolume,
|
|
|
|
Name: b.config.AMIName,
|
2019-05-03 17:47:09 -04:00
|
|
|
OriginalRegion: *ec2conn.Config.Region,
|
2017-02-27 08:51:38 -05:00
|
|
|
},
|
|
|
|
&awscommon.StepModifyAMIAttributes{
|
|
|
|
Description: b.config.AMIDescription,
|
|
|
|
Users: b.config.AMIUsers,
|
|
|
|
Groups: b.config.AMIGroups,
|
|
|
|
ProductCodes: b.config.AMIProductCodes,
|
|
|
|
SnapshotUsers: b.config.SnapshotUsers,
|
|
|
|
SnapshotGroups: b.config.SnapshotGroups,
|
|
|
|
Ctx: b.config.ctx,
|
2020-01-20 10:29:38 -05:00
|
|
|
GeneratedData: generatedData,
|
2017-02-27 08:51:38 -05:00
|
|
|
},
|
|
|
|
&awscommon.StepCreateTags{
|
|
|
|
Tags: b.config.AMITags,
|
|
|
|
SnapshotTags: b.config.SnapshotTags,
|
|
|
|
Ctx: b.config.ctx,
|
|
|
|
},
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run!
|
|
|
|
b.runner = common.NewRunner(steps, b.config.PackerConfig, ui)
|
2019-03-22 09:53:28 -04:00
|
|
|
b.runner.Run(ctx, state)
|
2016-12-30 16:21:23 -05:00
|
|
|
|
|
|
|
// If there was an error, return that
|
|
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
|
|
|
return nil, rawErr.(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
if amis, ok := state.GetOk("amis"); ok {
|
|
|
|
// Build the artifact and return it
|
|
|
|
artifact := &awscommon.Artifact{
|
|
|
|
Amis: amis.(map[string]string),
|
|
|
|
BuilderIdValue: BuilderId,
|
2017-12-19 14:04:17 -05:00
|
|
|
Session: session,
|
2020-01-16 06:04:03 -05:00
|
|
|
StateData: map[string]interface{}{"generated_data": state.Get("generated_data")},
|
2016-12-30 16:21:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return artifact, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|