Copilot commented on code in PR #340:
URL: 
https://github.com/apache/cloudstack-terraform-provider/pull/340#discussion_r3947591869


##########
cloudstack/resource_cloudstack_role_permission.go:
##########
@@ -242,28 +244,13 @@ func reconcileCloudStackRolePermissions(d 
*schema.ResourceData, meta interface{}
                rolePermissionsByID[rp.Id] = rp
        }
 
-       used := make(map[string]bool)
-       deleted := make(map[string]bool)
        managedIDs := make([]string, 0)
        managedIDSet := make(map[string]bool)
+       desiredPermissions := 
rolePermissionSpecs(d.Get("permission").([]interface{}))
+       matchedPermissions := matchCloudStackRolePermissions(rolePermissions, 
desiredPermissions)
 
-       for _, desired := range 
rolePermissionSpecs(d.Get("permission").([]interface{})) {
-               rp := rolePermissionsByID[desired.ID]
-               if rp != nil && (rp.Rule != desired.Rule || rp.Description != 
desired.Description) {
-                       if exactMatch := 
findMatchingRolePermission(rolePermissions, desired, used); exactMatch != nil {
-                               rp = exactMatch
-                       } else {
-                               if err := deleteCloudStackRolePermission(cs, 
rp.Id); err != nil {
-                                       return err
-                               }
-                               deleted[rp.Id] = true
-                               used[rp.Id] = true
-                               rp = nil
-                       }
-               } else if rp == nil {
-                       rp = findMatchingRolePermission(rolePermissions, 
desired, used)
-               }
-
+       for i, desired := range desiredPermissions {
+               rp := matchedPermissions[i]
                if rp == nil {
                        rp, err = createCloudStackRolePermission(cs, roleID, 
desired)
                        if err != nil {

Review Comment:
   `reconcileCloudStackRolePermissions` no longer handles description 
drift/changes. Since CloudStack's UpdateRolePermission call only updates the 
allow/deny flag, a description change must be implemented as delete+recreate; 
otherwise configs that change `description` (or out-of-band description 
changes) can leave the provider stuck with perpetual diffs or fail with 
duplicate-rule errors when trying to create the new permission before removing 
the old one.
   
   This issue also appears on line 439 of the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to