8000 Fix deletion of AWS::IAM::Policy by dominikschubert · Pull Request #9092 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Fix deletion of AWS::IAM::Policy #9092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix AWS::IAM::Policy
  • Loading branch information
dominikschubert committed Sep 7, 2023
commit 9ea1814c65239207a2f90c8c3d67dc96bc70d9b4
21 changes: 18 additions & 3 deletions localstack/services/iam/resource_providers/aws_iam_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def create(
policy_doc = json.dumps(util.remove_none_values(model["PolicyDocument"]))
policy_name = model["PolicyName"]

if not any([model.get("Roles"), model.get("Users"), model.get("Groups")]):
return ProgressEvent(
status=OperationStatus.FAILED,
resource_model={},
error_code="InvalidRequest",
message="At least one of [Groups,Roles,Users] must be non-empty.",
)

for role in model.get("Roles", []):
iam_client.put_role_policy(
RoleName=role, PolicyName=policy_name, PolicyDocument=policy_doc
Expand All @@ -83,8 +91,6 @@ def read(
) -> ProgressEvent[IAMPolicyProperties]:
"""
Fetch resource information


"""
raise NotImplementedError

Expand All @@ -96,7 +102,16 @@ def delete(
Delete a resource
"""
iam = request.aws_client_factory.iam
iam.delete_policy(PolicyArn=request.desired_state["Id"])

model = request.previous_state
policy_name = request.previous_state["PolicyName"]
for role in model.get("Roles", []):
iam.delete_role_policy(RoleName=role, PolicyName=policy_name)
for user in model.get("Users", []):
iam.delete_user_policy(UserName=user, PolicyName=policy_name)
for group in model.get("Groups", []):
iam.delete_group_policy(GroupName=group, PolicyName=policy_name)

return ProgressEvent(status=OperationStatus.SUCCESS, resource_model={})

def update(
Expand Down
0