Skip to content

Commit 50979f0

Browse files
committed
fix: Enhance network ACL rule creation & reading
This commit addresses multiple issues in the `cloudstack_network_acl_rule` resource to improve reliability and compatibility with configurations lacking port specifications: 1. **Fix `aclid` usage in `createNetworkACLRule`**: - Replaced `p.SetAclid(d.Id())` with `p.SetAclid(d.Get("acl_id").(string))` to use the configured `acl_id` instead of the unset resource ID during creation. This resolves CloudStack API error 431 (CSExceptionErrorCode: 9999) caused by an empty `aclid` value. 2. **Support TCP/UDP rules without ports**: - Modified `createNetworkACLRule` to create rules for TCP/UDP protocols when no ports are specified, using a default "all ports" rule with a UUID stored as `all_ports`. This ensures compatibility with configs omitting the optional `ports` attribute. - Updated `resourceCloudStackNetworkACLRuleRead` to handle TCP/UDP rules with no ports, adding them to the state even if the `ports` set is empty. 3. **Add retry logic for API consistency**: - Introduced retry logic in `resourceCloudStackNetworkACLRuleRead` using `retry.RetryContext` to handle eventual consistency in CloudStack's `ListNetworkACLs` API, retrying for up to 30 seconds if the API call fails or returns no rules. 4. **Improve validation in `verifyNetworkACLRuleParams`**: - Relaxed validation to allow empty `ports` for TCP/UDP protocols, aligning with the schema where `ports` is optional. This prevents validation errors for configs without ports. 5. **Enhance logging for debugging**: - Added detailed `[DEBUG]` and `[ERROR]` logs across `resourceCloudStackNetworkACLRuleCreate`, `createNetworkACLRules`, `createNetworkACLRule`, `resourceCloudStackNetworkACLRuleRead`, and `verifyNetworkACLRuleParams` to trace rule creation, validation, and API interactions. - Included rule indices and detailed error messages in `createNetworkACLRules` for better error reporting. 6. **Defer `d.SetId` in `Create`**: - Moved `d.SetId(d.Get("acl_id").(string))` in `resourceCloudStackNetworkACLRuleCreate` to after successful rule creation to avoid premature state updates. These changes resolve the "Provider produced inconsistent result after apply: Root object was present, but now absent" error by ensuring rules are created correctly and consistently read from CloudStack. The fixes also improve robustness for multi-rule configurations and eventual consistency scenarios.
1 parent 919a358 commit 50979f0

File tree

1 file changed

+197
-78
lines changed

1 file changed

+197
-78
lines changed

0 commit comments

Comments
 (0)