Skip to content

fix(gce-cleanup): add security-groups cleanup in the cleanup script - #238

Open
SimoneDutto wants to merge 1 commit into
juju:mainfrom
SimoneDutto:delete-security-groups-gcp
Open

fix(gce-cleanup): add security-groups cleanup in the cleanup script#238
SimoneDutto wants to merge 1 commit into
juju:mainfrom
SimoneDutto:delete-security-groups-gcp

Conversation

@SimoneDutto

@SimoneDutto SimoneDutto commented Oct 30, 2025

Copy link
Copy Markdown

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.

Add python script to cleanup security groups.
@SimoneDutto
SimoneDutto force-pushed the delete-security-groups-gcp branch from 574a20f to 665ce73 Compare October 30, 2025 14:39
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))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gfouillet
gfouillet self-requested a review October 30, 2025 14:57
@SimoneDutto

SimoneDutto commented Oct 30, 2025

Copy link
Copy Markdown
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

@wallyworld wallyworld left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants