Fixing a small bug in the ACL rule hash function

Since the default value is not available in the initial config (when
`action` or `traffic_type` is omitted), the result would be `nil`
instead of a string when trying to access one of these the values.
This commit is contained in:
Sander van Harmelen 2015-03-03 13:40:28 +01:00
parent 221b48bd5a
commit 033cee31f3
2 changed files with 17 additions and 3 deletions

View File

@ -455,12 +455,27 @@ func resourceCloudStackNetworkACLRuleDeleteRule(
func resourceCloudStackNetworkACLRuleHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
// This is a little ugly, but it's needed because these arguments have
// a default value that needs to be part of the string to hash
var action, trafficType string
if a, ok := m["action"]; ok {
action = a.(string)
} else {
action = "allow"
}
if t, ok := m["traffic_type"]; ok {
trafficType = t.(string)
} else {
trafficType = "ingress"
}
buf.WriteString(fmt.Sprintf(
"%s-%s-%s-%s-",
m["action"].(string),
action,
m["source_cidr"].(string),
m["protocol"].(string),
m["traffic_type"].(string)))
trafficType))
if v, ok := m["icmp_type"]; ok {
buf.WriteString(fmt.Sprintf("%d-", v.(int)))

View File

@ -190,7 +190,6 @@ resource "cloudstack_network_acl_rule" "foo" {
aclid = "${cloudstack_network_acl.foo.id}"
rule {
action = "allow"
source_cidr = "172.16.100.0/24"
protocol = "tcp"
ports = ["80", "443"]