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
I have bumped into the following issue when working with moto and cloudformation stacks.
Where a cloudformation template contains both an IAM role and a separate Inline policy, deletion of the stack with moto can intermittently fail.
The following code demonstrates the intermittent failure. The test runs the same code 10 times, but varies the logical resource id for the inline policy to demostrate the issue. When running you should see some tests pass and some tests fail. This is because the delete method in moto/cloudformation/parsing.py iterates over a set of resources to delete, the ordering of which isn't consistent between runs.
The ordering of resources matters. If the role is deleted first then the inline policy is left dangling and when moto tries to delete the inline policy an error like this is raised:
botocore.exceptions.ClientError: An error occurred (NoSuchEntity) when calling the DeleteStack operation: Role inline_policy_issue-Role-47BAI5OU6Q50 not found.
Note if the policy is deleted first, there is no error raised.
Varying the logical resource id for the inline policy resource on different runs causes the ordering of the remaining_resources set to vary between runs.
We could look at the moto.iam.models.InlinePolicy.unapply_policy logic.
def unapply_policy(self, backend: "IAMBackend") -> None:
if self.user_names:
for user_name in self.user_names:
backend.delete_user_policy(user_name, self.policy_name)
if self.role_names:
for role_name in self.role_names:
backend.delete_role_policy(role_name, self.policy_name)
if self.group_names:
for group_name in self.group_names:
backend.delete_group_policy(group_name, self.policy_name)
The inline policy potentially references users, groups and roles that may or may not exist in the cloudformation delete scenario. In each of the for loops a check could be added to verify existence of the user, group or role before trying to detach the policy.
The checks could alternatively be added to the delete_user_policy / delete_role_policy / delete_group_policy methods if that makes sense.
I have bumped into the following issue when working with moto and cloudformation stacks.
Where a cloudformation template contains both an IAM role and a separate Inline policy, deletion of the stack with moto can intermittently fail.
The following code demonstrates the intermittent failure. The test runs the same code 10 times, but varies the logical resource id for the inline policy to demostrate the issue. When running you should see some tests pass and some tests fail. This is because the delete method in moto/cloudformation/parsing.py iterates over a set of resources to delete, the ordering of which isn't consistent between runs.
The ordering of resources matters. If the role is deleted first then the inline policy is left dangling and when moto tries to delete the inline policy an error like this is raised:
botocore.exceptions.ClientError: An error occurred (NoSuchEntity) when calling the DeleteStack operation: Role inline_policy_issue-Role-47BAI5OU6Q50 not found.
Note if the policy is deleted first, there is no error raised.
Varying the logical resource id for the inline policy resource on different runs causes the ordering of the remaining_resources set to vary between runs.
The text was updated successfully, but these errors were encountered: