Skip to content

Commit

Permalink
providers/aws: changing order of security group cidrs doesn't affect
Browse files Browse the repository at this point in the history
things
  • Loading branch information
mitchellh committed Aug 21, 2014
1 parent 46b8158 commit cdc2a53
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions builtin/providers/aws/resource_aws_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"bytes"
"fmt"
"sort"
"log"
"time"

Expand Down Expand Up @@ -89,14 +90,30 @@ func resourceAwsSecurityGroupIngressHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%d-", m["to_port"].(int)))
buf.WriteString(fmt.Sprintf("%d-", m["protocol"].(string)))

// 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 v, ok := m["cidr_blocks"]; ok {
for _, raw := range v.([]interface{}) {
buf.WriteString(fmt.Sprintf("%s-", raw.(string)))
vs := v.([]interface{})
s := make([]string, len(vs))
for i, raw := range vs {
s[i] = raw.(string)
}
sort.Strings(s)

for _, v := range s {
buf.WriteString(fmt.Sprintf("%s-", v))
}
}
if v, ok := m["security_groups"]; ok {
for _, raw := range v.([]interface{}) {
buf.WriteString(fmt.Sprintf("%s-", raw.(string)))
vs := v.([]interface{})
s := make([]string, len(vs))
for i, raw := range vs {
s[i] = raw.(string)
}
sort.Strings(s)

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

Expand Down

0 comments on commit cdc2a53

Please sign in to comment.