From 201c8c1332bbeb1118ace869c11b0eaded826ee5 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 15 Apr 2019 16:44:56 -0700 Subject: [PATCH] make sure that you encrypt using the provided kms key id and not the default --- builder/amazon/chroot/builder.go | 1 + builder/amazon/common/step_ami_region_copy.go | 2 ++ builder/amazon/ebs/builder.go | 1 + builder/amazon/ebssurrogate/builder.go | 1 + builder/amazon/instance/builder.go | 1 + 5 files changed, 6 insertions(+) diff --git a/builder/amazon/chroot/builder.go b/builder/amazon/chroot/builder.go index 5dd679564..93151a1e5 100644 --- a/builder/amazon/chroot/builder.go +++ b/builder/amazon/chroot/builder.go @@ -280,6 +280,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &awscommon.StepAMIRegionCopy{ AccessConfig: &b.config.AccessConfig, Regions: b.config.AMIRegions, + AMIKmsKeyId: b.config.AMIKmsKeyId, RegionKeyIds: b.config.AMIRegionKMSKeyIDs, EncryptBootVolume: b.config.AMIEncryptBootVolume, Name: b.config.AMIName, diff --git a/builder/amazon/common/step_ami_region_copy.go b/builder/amazon/common/step_ami_region_copy.go index 380c88d8d..d5316c4a0 100644 --- a/builder/amazon/common/step_ami_region_copy.go +++ b/builder/amazon/common/step_ami_region_copy.go @@ -14,6 +14,7 @@ import ( type StepAMIRegionCopy struct { AccessConfig *AccessConfig Regions []string + AMIKmsKeyId string RegionKeyIds map[string]string EncryptBootVolume *bool // nil means preserve Name string @@ -31,6 +32,7 @@ func (s *StepAMIRegionCopy) Run(ctx context.Context, state multistep.StateBag) m // AMI with required encryption setting. // temp image was created by stepCreateAMI. s.Regions = append(s.Regions, *ec2conn.Config.Region) + s.RegionKeyIds[*ec2conn.Config.Region] = s.AMIKmsKeyId } if len(s.Regions) == 0 { diff --git a/builder/amazon/ebs/builder.go b/builder/amazon/ebs/builder.go index e196cb6d4..b34575ed1 100644 --- a/builder/amazon/ebs/builder.go +++ b/builder/amazon/ebs/builder.go @@ -223,6 +223,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &awscommon.StepAMIRegionCopy{ AccessConfig: &b.config.AccessConfig, Regions: b.config.AMIRegions, + AMIKmsKeyId: b.config.AMIKmsKeyId, RegionKeyIds: b.config.AMIRegionKMSKeyIDs, EncryptBootVolume: b.config.AMIEncryptBootVolume, Name: b.config.AMIName, diff --git a/builder/amazon/ebssurrogate/builder.go b/builder/amazon/ebssurrogate/builder.go index 12899cad4..e5d042c9f 100644 --- a/builder/amazon/ebssurrogate/builder.go +++ b/builder/amazon/ebssurrogate/builder.go @@ -248,6 +248,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &awscommon.StepAMIRegionCopy{ AccessConfig: &b.config.AccessConfig, Regions: b.config.AMIRegions, + AMIKmsKeyId: b.config.AMIKmsKeyId, RegionKeyIds: b.config.AMIRegionKMSKeyIDs, EncryptBootVolume: b.config.AMIEncryptBootVolume, Name: b.config.AMIName, diff --git a/builder/amazon/instance/builder.go b/builder/amazon/instance/builder.go index 86fac7538..6481102b9 100644 --- a/builder/amazon/instance/builder.go +++ b/builder/amazon/instance/builder.go @@ -299,6 +299,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack &awscommon.StepAMIRegionCopy{ AccessConfig: &b.config.AccessConfig, Regions: b.config.AMIRegions, + AMIKmsKeyId: b.config.AMIKmsKeyId, RegionKeyIds: b.config.AMIRegionKMSKeyIDs, EncryptBootVolume: b.config.AMIEncryptBootVolume, Name: b.config.AMIName,