diff --git a/builder/alicloud/ecs/step_create_instance.go b/builder/alicloud/ecs/step_create_instance.go index 31b4a91e7..909720e2d 100644 --- a/builder/alicloud/ecs/step_create_instance.go +++ b/builder/alicloud/ecs/step_create_instance.go @@ -145,7 +145,7 @@ func (s *stepCreateAlicloudInstance) buildCreateInstanceRequest(state multistep. if s.IOOptimized.True() { request.IoOptimized = IOOptimizedOptimized - } else if IOOptimized.False() { + } else if s.IOOptimized.False() { request.IoOptimized = IOOptimizedNone } diff --git a/builder/amazon/common/ami_config_test.go b/builder/amazon/common/ami_config_test.go index b1057673b..8430c964c 100644 --- a/builder/amazon/common/ami_config_test.go +++ b/builder/amazon/common/ami_config_test.go @@ -178,7 +178,7 @@ func TestAMIConfigPrepare_Share_EncryptedBoot(t *testing.T) { func TestAMIConfigPrepare_ValidateKmsKey(t *testing.T) { c := testAMIConfig() - c.AMIEncryptBootVolume = aws.Bool(true) + c.AMIEncryptBootVolume = config.TriTrue accessConf := testAccessConfig() diff --git a/builder/amazon/common/block_device_test.go b/builder/amazon/common/block_device_test.go index b2c655110..a390c805b 100644 --- a/builder/amazon/common/block_device_test.go +++ b/builder/amazon/common/block_device_test.go @@ -6,6 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/packer/helper/config" ) func TestBlockDevice(t *testing.T) { @@ -71,7 +72,7 @@ func TestBlockDevice(t *testing.T) { VolumeType: "gp2", VolumeSize: 8, DeleteOnTermination: true, - Encrypted: aws.Bool(true), + Encrypted: config.TriTrue, }, Result: &ec2.BlockDeviceMapping{ @@ -90,7 +91,7 @@ func TestBlockDevice(t *testing.T) { VolumeType: "gp2", VolumeSize: 8, DeleteOnTermination: true, - Encrypted: aws.Bool(true), + Encrypted: config.TriTrue, KmsKeyId: "2Fa48a521f-3aff-4b34-a159-376ac5d37812", }, diff --git a/builder/amazon/common/step_ami_region_copy.go b/builder/amazon/common/step_ami_region_copy.go index ca77c6e63..323a9a0db 100644 --- a/builder/amazon/common/step_ami_region_copy.go +++ b/builder/amazon/common/step_ami_region_copy.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" + "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -17,7 +18,7 @@ type StepAMIRegionCopy struct { Regions []string AMIKmsKeyId string RegionKeyIds map[string]string - EncryptBootVolume *bool // nil means preserve + EncryptBootVolume config.Trilean // nil means preserve Name string OriginalRegion string @@ -74,7 +75,7 @@ func (s *StepAMIRegionCopy) Run(ctx context.Context, state multistep.StateBag) m s.toDelete = ami } - if s.EncryptBootVolume != nil && *s.EncryptBootVolume { + if s.EncryptBootVolume.True() { // encrypt_boot is true, so we have to copy the temporary // AMI with required encryption setting. // temp image was created by stepCreateAMI. @@ -102,7 +103,7 @@ func (s *StepAMIRegionCopy) Run(ctx context.Context, state multistep.StateBag) m var regKeyID string ui.Message(fmt.Sprintf("Copying to: %s", region)) - if s.EncryptBootVolume != nil && *s.EncryptBootVolume { + if s.EncryptBootVolume.True() { // Encrypt is true, explicitly regKeyID = s.RegionKeyIds[region] } else { @@ -112,7 +113,9 @@ func (s *StepAMIRegionCopy) Run(ctx context.Context, state multistep.StateBag) m go func(region string) { defer wg.Done() - id, snapshotIds, err := s.amiRegionCopy(ctx, state, s.AccessConfig, s.Name, ami, region, s.OriginalRegion, regKeyID, s.EncryptBootVolume) + id, snapshotIds, err := s.amiRegionCopy(ctx, state, s.AccessConfig, + s.Name, ami, region, s.OriginalRegion, regKeyID, + s.EncryptBootVolume.ToBoolPointer()) lock.Lock() defer lock.Unlock() amis[region] = id diff --git a/builder/amazon/common/step_ami_region_copy_test.go b/builder/amazon/common/step_ami_region_copy_test.go index 2e1628aab..9fc636519 100644 --- a/builder/amazon/common/step_ami_region_copy_test.go +++ b/builder/amazon/common/step_ami_region_copy_test.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2/ec2iface" + "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" ) @@ -109,7 +110,7 @@ func TestStepAMIRegionCopy_duplicates(t *testing.T) { AMIKmsKeyId: "12345", // Original region key in regionkeyids is different than in amikmskeyid RegionKeyIds: map[string]string{"us-east-1": "12345"}, - EncryptBootVolume: aws.Bool(true), + EncryptBootVolume: config.TriTrue, Name: "fake-ami-name", OriginalRegion: "us-east-1", } @@ -153,7 +154,7 @@ func TestStepAMIRegionCopy_duplicates(t *testing.T) { stepAMIRegionCopy = StepAMIRegionCopy{ AccessConfig: testAccessConfig(), Regions: []string{"us-east-1"}, - EncryptBootVolume: aws.Bool(false), + EncryptBootVolume: config.TriFalse, Name: "fake-ami-name", OriginalRegion: "us-east-1", } @@ -179,7 +180,7 @@ func TestStepAMIRegionCopy_duplicates(t *testing.T) { AMIKmsKeyId: "IlikePancakes", // Original region key in regionkeyids is different than in amikmskeyid RegionKeyIds: map[string]string{"us-east-1": "12345", "us-west-2": "abcde", "ap-east-1": "xyz"}, - EncryptBootVolume: aws.Bool(true), + EncryptBootVolume: config.TriTrue, Name: "fake-ami-name", OriginalRegion: "us-east-1", } @@ -226,7 +227,7 @@ func TestStepAmiRegionCopy_nil_encryption(t *testing.T) { Regions: make([]string, 0), AMIKmsKeyId: "", RegionKeyIds: make(map[string]string), - EncryptBootVolume: nil, + EncryptBootVolume: config.TriUnset, Name: "fake-ami-name", OriginalRegion: "us-east-1", } @@ -252,7 +253,7 @@ func TestStepAmiRegionCopy_true_encryption(t *testing.T) { Regions: make([]string, 0), AMIKmsKeyId: "", RegionKeyIds: make(map[string]string), - EncryptBootVolume: aws.Bool(true), + EncryptBootVolume: config.TriTrue, Name: "fake-ami-name", OriginalRegion: "us-east-1", } @@ -278,7 +279,7 @@ func TestStepAmiRegionCopy_nil_intermediary(t *testing.T) { Regions: make([]string, 0), AMIKmsKeyId: "", RegionKeyIds: make(map[string]string), - EncryptBootVolume: aws.Bool(false), + EncryptBootVolume: config.TriFalse, Name: "fake-ami-name", OriginalRegion: "us-east-1", } @@ -360,7 +361,7 @@ func TestStepAmiRegionCopy_AMISkipBuildRegion(t *testing.T) { Name: "fake-ami-name", OriginalRegion: "us-east-1", AMISkipBuildRegion: false, - EncryptBootVolume: aws.Bool(true), + EncryptBootVolume: config.TriTrue, } // mock out the region connection code stepAMIRegionCopy.getRegionConn = getMockConn @@ -386,7 +387,7 @@ func TestStepAmiRegionCopy_AMISkipBuildRegion(t *testing.T) { Name: "fake-ami-name", OriginalRegion: "us-east-1", AMISkipBuildRegion: true, - EncryptBootVolume: aws.Bool(true), + EncryptBootVolume: config.TriTrue, } // mock out the region connection code stepAMIRegionCopy.getRegionConn = getMockConn