Skip to content

Commit

Permalink
Merge pull request #13679 from terraform-providers/ap_unparam_linting…
Browse files Browse the repository at this point in the history
…_security_group

resource/security_group: remove unused error return param
  • Loading branch information
anGie44 authored Jun 12, 2020
2 parents c20841f + 6a240da commit 2cc4254
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 30 deletions.
28 changes: 7 additions & 21 deletions aws/import_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ func resourceAwsSecurityGroupImportStatePerm(sg *ec2.SecurityGroup, ruleType str
IpRanges: perm.IpRanges,
}

r, err := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
if err != nil {
return nil, err
}
r := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
result = append(result, r)
}

Expand All @@ -100,10 +97,7 @@ func resourceAwsSecurityGroupImportStatePerm(sg *ec2.SecurityGroup, ruleType str
Ipv6Ranges: perm.Ipv6Ranges,
}

r, err := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
if err != nil {
return nil, err
}
r := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
result = append(result, r)
}

Expand All @@ -117,10 +111,7 @@ func resourceAwsSecurityGroupImportStatePerm(sg *ec2.SecurityGroup, ruleType str
UserIdGroupPairs: []*ec2.UserIdGroupPair{pair},
}

r, err := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
if err != nil {
return nil, err
}
r := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
result = append(result, r)
}
}
Expand All @@ -133,17 +124,14 @@ func resourceAwsSecurityGroupImportStatePerm(sg *ec2.SecurityGroup, ruleType str
ToPort: perm.ToPort,
}

r, err := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
if err != nil {
return nil, err
}
r := resourceAwsSecurityGroupImportStatePermPair(sg, ruleType, p)
result = append(result, r)
}

return result, nil
}

func resourceAwsSecurityGroupImportStatePermPair(sg *ec2.SecurityGroup, ruleType string, perm *ec2.IpPermission) (*schema.ResourceData, error) {
func resourceAwsSecurityGroupImportStatePermPair(sg *ec2.SecurityGroup, ruleType string, perm *ec2.IpPermission) *schema.ResourceData {
// Construct the rule. We do this by populating the absolute
// minimum necessary for Refresh on the rule to work. This
// happens to be a lot of fields since they're almost all needed
Expand Down Expand Up @@ -184,9 +172,7 @@ func resourceAwsSecurityGroupImportStatePermPair(sg *ec2.SecurityGroup, ruleType
}
}

if err := setFromIPPerm(d, sg, perm); err != nil {
return nil, fmt.Errorf("Error importing AWS Security Group: %s", err)
}
setFromIPPerm(d, sg, perm)

return d, nil
return d
}
21 changes: 12 additions & 9 deletions aws/resource_aws_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,8 @@ func resourceAwsSecurityGroupRuleRead(d *schema.ResourceData, meta interface{})
log.Printf("[DEBUG] Found rule for Security Group Rule (%s): %s", d.Id(), rule)

d.Set("type", ruleType)
if err := setFromIPPerm(d, sg, p); err != nil {
return fmt.Errorf("Error setting IP Permission for Security Group Rule: %s", err)
}

setFromIPPerm(d, sg, p)

d.Set("description", descriptionFromIPPerm(d, rule))

Expand Down Expand Up @@ -732,8 +731,8 @@ func expandIPPerm(d *schema.ResourceData, sg *ec2.SecurityGroup) (*ec2.IpPermiss
return &perm, nil
}

func setFromIPPerm(d *schema.ResourceData, sg *ec2.SecurityGroup, rule *ec2.IpPermission) error {
isVPC := sg.VpcId != nil && *sg.VpcId != ""
func setFromIPPerm(d *schema.ResourceData, sg *ec2.SecurityGroup, rule *ec2.IpPermission) {
isVPC := aws.StringValue(sg.VpcId) != ""

d.Set("from_port", rule.FromPort)
d.Set("to_port", rule.ToPort)
Expand Down Expand Up @@ -778,8 +777,6 @@ func setFromIPPerm(d *schema.ResourceData, sg *ec2.SecurityGroup, rule *ec2.IpPe
d.Set("source_security_group_id", s.GroupName)
}
}

return nil
}

func descriptionFromIPPerm(d *schema.ResourceData, rule *ec2.IpPermission) string {
Expand Down Expand Up @@ -1005,8 +1002,14 @@ func populateSecurityGroupRuleFromImport(d *schema.ResourceData, importParts []s
sgID := importParts[0]
ruleType := importParts[1]
protocol := importParts[2]
fromPort, _ := strconv.Atoi(importParts[3])
toPort, _ := strconv.Atoi(importParts[4])
fromPort, err := strconv.Atoi(importParts[3])
if err != nil {
return err
}
toPort, err := strconv.Atoi(importParts[4])
if err != nil {
return err
}
sources := importParts[5:]

d.Set("security_group_id", sgID)
Expand Down

0 comments on commit 2cc4254

Please sign in to comment.