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

fixing some edge cases with AWS SG Rules #1969

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 22 additions & 2 deletions builtin/providers/aws/resource_aws_security_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,14 @@ func resourceAwsSecurityGroupRuleRead(d *schema.ResourceData, meta interface{})
d.Set("cidr_blocks", cb)

if len(rule.UserIDGroupPairs) > 0 {
s := rule.UserIDGroupPairs[0]
d.Set("source_security_group_id", *s.GroupID)
// Can not use rule.UserIDGroupPairs[0] since if self=true is specifed
// then there will may be multiple objects in list.
for _, s := range rule.UserIDGroupPairs {
if *s.GroupID != sg_id {
d.Set("source_security_group_id", *s.GroupID)
break
}
}
}

return nil
Expand Down Expand Up @@ -272,6 +278,20 @@ func ipPermissionIDHash(ruleType string, ip *ec2.IPPermission) string {
}
buf.WriteString(fmt.Sprintf("%s-", ruleType))

// Need to include Peer security group IDs
// to avoid collisions.
if len(ip.UserIDGroupPairs) > 0 {
s := make([]string, len(ip.UserIDGroupPairs))
for i, r := range ip.UserIDGroupPairs {
s[i] = *r.GroupID
}
sort.Strings(s)

for _, v := range s {
buf.WriteString(fmt.Sprintf("%s-", v))
}
}

// We need to make sure to sort the strings below so that we always
// generate the same hash code no matter what is in the set.
if len(ip.IPRanges) > 0 {
Expand Down