You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix ACL ruleset Read function to prevent state mutation and handle out-of-band rules correctly
Two important fixes:
1. Create new rule maps instead of mutating existing state
- The Read function was directly modifying rule maps from the state
- This could cause Terraform to see spurious changes
- Now creates fresh maps with updated values from the API
2. Don't persist out-of-band rules as dummy entries in state
- Previously, unknown rules in managed mode were added as dummy rules
- This polluted the state with fake entries
- Now logs warnings about out-of-band rules but doesn't add them to state
- The Update function will delete them on the next apply
@@ -449,30 +453,17 @@ func resourceCloudStackNetworkACLRulesetRead(d *schema.ResourceData, meta interf
449
453
}
450
454
}
451
455
452
-
// If this is a managed resource, add all unknown rules to dummy rules
456
+
// If this is a managed resource and there are unknown rules (out-of-band rules),
457
+
// log them but DON'T add them to the state. They will be deleted on the next apply.
453
458
managed:=d.Get("managed").(bool)
454
459
ifmanaged&&len(ruleMap) >0 {
455
-
foruuid:=rangeruleMap {
456
-
// Make a dummy rule to hold the unknown UUID
457
-
cidrs:=&schema.Set{F: schema.HashString}
458
-
cidrs.Add(uuid)
459
-
460
-
rule:=map[string]interface{}{
461
-
"cidr_list": cidrs,
462
-
"protocol": uuid,
463
-
"uuid": uuid,
464
-
"rule_number": 0,
465
-
"action": "allow",
466
-
"traffic_type": "ingress",
467
-
"icmp_type": 0,
468
-
"icmp_code": 0,
469
-
"description": "",
470
-
"port": "",
471
-
}
472
-
473
-
// Add the dummy rule to the rules set
474
-
rules.Add(rule)
460
+
log.Printf("[WARN] Found %d out-of-band ACL rules for ACL %s that are not managed by Terraform. These will be deleted on the next apply.", len(ruleMap), d.Id())
0 commit comments