fix(gce-cleanup): add security-groups cleanup in the cleanup script - #238
Open
SimoneDutto wants to merge 1 commit into
Open
fix(gce-cleanup): add security-groups cleanup in the cleanup script#238SimoneDutto wants to merge 1 commit into
SimoneDutto wants to merge 1 commit into
Conversation
Add python script to cleanup security groups.
SimoneDutto
force-pushed
the
delete-security-groups-gcp
branch
from
October 30, 2025 14:39
574a20f to
665ce73
Compare
SimoneDutto
commented
Oct 30, 2025
Comment on lines
+144
to
+150
| for group in groups: | ||
| if not dry_run: | ||
| try: | ||
| if client.ex_destroy_firewall(group): | ||
| log.debug('Deleted security group {}'.format(group)) | ||
| except Exception as e: | ||
| log.debug('Attempted delete of security group {}, may still be in use: {}'.format(group, e)) |
Author
There was a problem hiding this comment.
gfouillet
self-requested a review
October 30, 2025 14:57
Author
|
Although i cannot find the exact the documentation where it's crystal clear that deleting a rule with an association to an instance will return an error on gcp, so i'm still experimenting. For AWS is super clear: https://docs.aws.amazon.com/cli/latest/reference/ec2/delete-security-group.html |
gfouillet
approved these changes
Oct 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add python script to cleanup security groups.
Before there was a TODO intending that since we don't store files between runs we can't compute the diff between old and new.
Now: I've used the same approach as the aws cleanup, where we get all security group with a prefix and we try to delete everything.
QA
gcloud compute firewall-rules create rule-to-test-delete --allow=tcp:9999 --source-ranges="192.168.1.0/24" --description="test firewall rule to delete"python3 jobs/z-jobs/scripts/gce.py --sa-email <redacted> --project-id <redacted> --pem-path <redacted> --dry-run delete-security-groups 'rule'-> and you should see the rule in stdout
python3 jobs/z-jobs/scripts/gce.py --sa-email <redacted> --project-id <redacted> --pem-path <redacted> delete-security-groups 'rule'-> and now the rule is gone.