amazon/builder: Move port validation for security group into RunConfig.Prepare

This commit is contained in:
Wilken Rivera 2020-04-24 09:20:18 -04:00
parent 3f6b28b70c
commit 2f09b74587
2 changed files with 9 additions and 9 deletions

View File

@ -427,6 +427,13 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
// Validation // Validation
errs := c.Comm.Prepare(ctx) 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 // Copy singular tag maps
errs = append(errs, c.RunTag.CopyOn(&c.RunTags)...) errs = append(errs, c.RunTag.CopyOn(&c.RunTags)...)
errs = append(errs, c.SpotTag.CopyOn(&c.SpotTags)...) errs = append(errs, c.SpotTag.CopyOn(&c.SpotTags)...)

View File

@ -77,14 +77,6 @@ func (s *StepSecurityGroup) Run(ctx context.Context, state multistep.StateBag) m
return multistep.ActionContinue 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 // Create the group
groupName := fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) groupName := fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID())
ui.Say(fmt.Sprintf("Creating temporary security group for this instance: %s", groupName)) 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 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{ groupRules := &ec2.AuthorizeSecurityGroupIngressInput{
GroupId: groupResp.GroupId, GroupId: groupResp.GroupId,
IpPermissions: []*ec2.IpPermission{ IpPermissions: []*ec2.IpPermission{