amazon/builder: Move port validation for security group into RunConfig.Prepare
This commit is contained in:
parent
3f6b28b70c
commit
2f09b74587
|
@ -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)...)
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue