providers/aws: changing order of security group cidrs doesn't affect

things
This commit is contained in:
Mitchell Hashimoto 2014-08-21 14:10:09 -07:00
parent 46b81587ef
commit cdc2a53553
1 changed files with 21 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package aws
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"sort"
"log" "log"
"time" "time"
@ -89,14 +90,30 @@ func resourceAwsSecurityGroupIngressHash(v interface{}) int {
buf.WriteString(fmt.Sprintf("%d-", m["to_port"].(int))) buf.WriteString(fmt.Sprintf("%d-", m["to_port"].(int)))
buf.WriteString(fmt.Sprintf("%d-", m["protocol"].(string))) 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 { if v, ok := m["cidr_blocks"]; ok {
for _, raw := range v.([]interface{}) { vs := v.([]interface{})
buf.WriteString(fmt.Sprintf("%s-", raw.(string))) 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 { if v, ok := m["security_groups"]; ok {
for _, raw := range v.([]interface{}) { vs := v.([]interface{})
buf.WriteString(fmt.Sprintf("%s-", raw.(string))) 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))
} }
} }