diff --git a/builder/amazon/common/run_config.go b/builder/amazon/common/run_config.go index be1596164..feaea4e1b 100644 --- a/builder/amazon/common/run_config.go +++ b/builder/amazon/common/run_config.go @@ -427,6 +427,13 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { // Validation errs := c.Comm.Prepare(ctx) + if port := c.Comm.Port(); port == 0 { + if c.Comm.Type != "none" { + err := fmt.Errorf("port must be set to a non-zero value for a communicator of type %s", c.Comm.Type) + errs = append(errs, err) + } + } + // Copy singular tag maps errs = append(errs, c.RunTag.CopyOn(&c.RunTags)...) errs = append(errs, c.SpotTag.CopyOn(&c.SpotTags)...) diff --git a/builder/amazon/common/step_security_group.go b/builder/amazon/common/step_security_group.go index 09ec34400..2b5ddaf7e 100644 --- a/builder/amazon/common/step_security_group.go +++ b/builder/amazon/common/step_security_group.go @@ -77,14 +77,6 @@ func (s *StepSecurityGroup) Run(ctx context.Context, state multistep.StateBag) m return multistep.ActionContinue } - // TODO move to some prevalidation step for - port := s.CommConfig.Port() - if port == 0 { - if s.CommConfig.Type != "none" { - panic("port must be set to a non-zero value.") - } - } - // Create the group groupName := fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) ui.Say(fmt.Sprintf("Creating temporary security group for this instance: %s", groupName)) @@ -138,7 +130,8 @@ func (s *StepSecurityGroup) Run(ctx context.Context, state multistep.StateBag) m return multistep.ActionContinue } - // Authorize the SSH access for the security group + port := s.CommConfig.Port() + // Authorize access for the provided port within the security group groupRules := &ec2.AuthorizeSecurityGroupIngressInput{ GroupId: groupResp.GroupId, IpPermissions: []*ec2.IpPermission{