Skip to content

Commit bdfa430

Browse files
Fix managed=true unknown-rule handling for ruleset
- Adjust dummy rule format for ruleset to use 'uuid' string instead of 'uuids' map - Add rule_number to dummy rules for ruleset (required field) - Find highest existing rule_number and assign dummy rules starting from max+1 - Prevents conflicts between dummy rules and user-defined rules - Addresses review comment about managed mode incompatibility with ruleset
1 parent 20b8359 commit bdfa430

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

cloudstack/resource_cloudstack_network_acl_rule.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,21 +954,48 @@ func resourceCloudStackNetworkACLRuleRead(d *schema.ResourceData, meta interface
954954
// If this is a managed firewall, add all unknown rules into dummy rules
955955
managed := d.Get("managed").(bool)
956956
if managed && len(ruleMap) > 0 {
957+
// Find the highest rule_number to avoid conflicts when creating dummy rules
958+
maxRuleNumber := 0
959+
for _, rule := range rules {
960+
if ruleMap, ok := rule.(map[string]interface{}); ok {
961+
if ruleNum, ok := ruleMap["rule_number"].(int); ok && ruleNum > maxRuleNumber {
962+
maxRuleNumber = ruleNum
963+
}
964+
}
965+
}
966+
967+
// Start assigning dummy rule numbers after the highest existing rule_number
968+
dummyRuleNumber := maxRuleNumber + 1
969+
957970
for uuid := range ruleMap {
958971
// We need to create and add a dummy value to a list as the
959972
// cidr_list is a required field and thus needs a value
960973
cidrs := []interface{}{uuid}
961974

962975
// Make a dummy rule to hold the unknown UUID
963-
rule := map[string]interface{}{
964-
"cidr_list": cidrs,
965-
"protocol": uuid,
966-
"uuids": map[string]interface{}{uuid: uuid},
976+
// Format differs between 'rule' and 'ruleset'
977+
var rule map[string]interface{}
978+
if usingRuleset {
979+
// For ruleset: use 'uuid' string and include rule_number
980+
rule = map[string]interface{}{
981+
"cidr_list": cidrs,
982+
"protocol": uuid,
983+
"uuid": uuid,
984+
"rule_number": dummyRuleNumber,
985+
}
986+
dummyRuleNumber++
987+
} else {
988+
// For rule: use 'uuids' map
989+
rule = map[string]interface{}{
990+
"cidr_list": cidrs,
991+
"protocol": uuid,
992+
"uuids": map[string]interface{}{uuid: uuid},
993+
}
967994
}
968995

969996
// Add the dummy rule to the rules list
970997
rules = append(rules, rule)
971-
log.Printf("[DEBUG] Added managed dummy rule for UUID %s", uuid)
998+
log.Printf("[DEBUG] Added managed dummy rule for UUID %s (usingRuleset=%t)", uuid, usingRuleset)
972999
}
9731000
}
9741001

0 commit comments

Comments
 (0)