allow validation to pass when subnet filters are present
This commit is contained in:
parent
fce24ca71d
commit
4fb0de5256
|
@ -23,6 +23,7 @@ type StepPreValidate struct {
|
|||
AMISkipBuildRegion bool
|
||||
VpcId string
|
||||
SubnetId string
|
||||
HasSubnetFilter bool
|
||||
}
|
||||
|
||||
func (s *StepPreValidate) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
|
@ -121,10 +122,11 @@ func (s *StepPreValidate) Run(ctx context.Context, state multistep.StateBag) mul
|
|||
}
|
||||
|
||||
func (s *StepPreValidate) checkVpc(conn ec2iface.EC2API) error {
|
||||
if s.VpcId == "" || (s.VpcId != "" && s.SubnetId != "") {
|
||||
if s.VpcId == "" || (s.VpcId != "" && (s.SubnetId != "" || s.HasSubnetFilter)) {
|
||||
// Skip validation if:
|
||||
// * The user has not provided a VpcId.
|
||||
// * Both VpcId and SubnetId are provided; AWS API will error if something is wrong.
|
||||
// * Both VpcId and SubnetFilter are provided
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -135,7 +137,7 @@ func (s *StepPreValidate) checkVpc(conn ec2iface.EC2API) error {
|
|||
|
||||
if res != nil && len(res.Vpcs) == 1 && res.Vpcs[0] != nil {
|
||||
if isDefault := aws.BoolValue(res.Vpcs[0].IsDefault); !isDefault {
|
||||
return fmt.Errorf("Error: subnet_id must be provided for non-default VPCs (%s)", s.VpcId)
|
||||
return fmt.Errorf("Error: subnet_id or subnet_filter must be provided for non-default VPCs (%s)", s.VpcId)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -45,6 +45,7 @@ func TestStepPreValidate_checkVpc(t *testing.T) {
|
|||
{"NonDefaultVpcWithSubnet", StepPreValidate{VpcId: "vpc-1234567890", SubnetId: "subnet-1234567890"}, false},
|
||||
{"SubnetWithNoVpc", StepPreValidate{SubnetId: "subnet-1234567890"}, false},
|
||||
{"NoVpcInformation", StepPreValidate{}, false},
|
||||
{"NonDefaultVpcWithSubnetFilter", StepPreValidate{VpcId: "vpc-1234567890", HasSubnetFilter: true}, false},
|
||||
}
|
||||
|
||||
mockConn, err := getMockConn(nil, "")
|
||||
|
|
|
@ -209,6 +209,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
AMISkipBuildRegion: b.config.AMISkipBuildRegion,
|
||||
VpcId: b.config.VpcId,
|
||||
SubnetId: b.config.SubnetId,
|
||||
HasSubnetFilter: len(b.config.SubnetFilter.Filters) > 0,
|
||||
},
|
||||
&awscommon.StepSourceAMIInfo{
|
||||
SourceAmi: b.config.SourceAmi,
|
||||
|
|
|
@ -232,6 +232,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
ForceDeregister: b.config.AMIForceDeregister,
|
||||
VpcId: b.config.VpcId,
|
||||
SubnetId: b.config.SubnetId,
|
||||
HasSubnetFilter: len(b.config.SubnetFilter.Filters) > 0,
|
||||
},
|
||||
&awscommon.StepSourceAMIInfo{
|
||||
SourceAmi: b.config.SourceAmi,
|
||||
|
|
|
@ -294,6 +294,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
|||
ForceDeregister: b.config.AMIForceDeregister,
|
||||
VpcId: b.config.VpcId,
|
||||
SubnetId: b.config.SubnetId,
|
||||
HasSubnetFilter: len(b.config.SubnetFilter.Filters) > 0,
|
||||
},
|
||||
&awscommon.StepSourceAMIInfo{
|
||||
SourceAmi: b.config.SourceAmi,
|
||||
|
|
Loading…
Reference in New Issue