From b80e1d51c6f5538d7f31a2cf01c5028f68a1a62c Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Mon, 3 Sep 2018 15:01:14 +0200 Subject: [PATCH] aws: when building an AMI with 'encrypt_boot: true', randomize the name of the temporary AMI --- builder/amazon/ebs/step_create_ami.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/builder/amazon/ebs/step_create_ami.go b/builder/amazon/ebs/step_create_ami.go index 1d081db70..8d9049f85 100644 --- a/builder/amazon/ebs/step_create_ami.go +++ b/builder/amazon/ebs/step_create_ami.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" awscommon "github.com/hashicorp/packer/builder/amazon/common" + "github.com/hashicorp/packer/common/random" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -22,10 +23,17 @@ func (s *stepCreateAMI) Run(ctx context.Context, state multistep.StateBag) multi ui := state.Get("ui").(packer.Ui) // Create the image - ui.Say(fmt.Sprintf("Creating the AMI: %s", config.AMIName)) + amiName := config.AMIName + if config.AMIEncryptBootVolume { + // to avoid having a temporary unencrypted + // image named config.AMIName + amiName = random.AlphaNum(7) + } + + ui.Say(fmt.Sprintf("Creating unencrypted AMI %s from instance %s", amiName, *instance.InstanceId)) createOpts := &ec2.CreateImageInput{ InstanceId: instance.InstanceId, - Name: &config.AMIName, + Name: &amiName, BlockDeviceMappings: config.BlockDevices.BuildAMIDevices(), }