From 074be9942d6b96e247efcd9734ee6310ae795ac3 Mon Sep 17 00:00:00 2001 From: DanHam Date: Tue, 19 Nov 2019 14:05:24 +0000 Subject: [PATCH 1/2] Only validate the user has provided a subnet_id when vpc_id has been set --- builder/amazon/common/step_pre_validate.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builder/amazon/common/step_pre_validate.go b/builder/amazon/common/step_pre_validate.go index ae0c6d41c..e11f122cc 100644 --- a/builder/amazon/common/step_pre_validate.go +++ b/builder/amazon/common/step_pre_validate.go @@ -121,8 +121,10 @@ func (s *StepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul } func (s *StepPreValidate) checkVpc(conn ec2iface.EC2API) error { - if s.VpcId != "" && s.SubnetId != "" { - // skip validation if both VpcId and SubnetId are provided; AWS API will error if something is wrong. + if s.VpcId == "" || (s.VpcId != "" && s.SubnetId != "") { + // Skip validation if: + // * The user has not provided a VpcId. + // * Both VpcId and SubnetId are provided; AWS API will error if something is wrong. return nil } From afb880c134a46c525a740169be24192ba2837916 Mon Sep 17 00:00:00 2001 From: nywilken Date: Tue, 19 Nov 2019 14:32:54 -0500 Subject: [PATCH 2/2] test/builder/amazon/common/step_pre_validate: Update DescribeVpcs mock * Update condition to check for a empty VpcId --- builder/amazon/common/step_pre_validate_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/builder/amazon/common/step_pre_validate_test.go b/builder/amazon/common/step_pre_validate_test.go index 95448fc21..cb66b76e7 100644 --- a/builder/amazon/common/step_pre_validate_test.go +++ b/builder/amazon/common/step_pre_validate_test.go @@ -11,11 +11,8 @@ import ( //DescribeVpcs mocks an ec2.DescribeVpcsOutput for a given input func (m *mockEC2Conn) DescribeVpcs(input *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error) { - m.lock.Lock() - m.copyImageCount++ - m.lock.Unlock() - if input == nil || len(input.VpcIds) == 0 { + if input == nil || aws.StringValue(input.VpcIds[0]) == "" { return nil, fmt.Errorf("oops looks like we need more input") }