Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/security_group: remove unused error return param #13679

Merged
merged 4 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -326,9 +326,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 @@ -731,8 +730,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 @@ -777,8 +776,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 @@ -1004,8 +1001,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