Skip to content

Instantly share code, notes, and snippets.

@sorakiu
sorakiu / generate_gcp_firewall_rules.py
Last active October 7, 2025 11:16
Block specific countries from reaching a compute instance in GCP using IP2LOCATION-LITE-DB1.CIDR.CSV
# Requires gcloud CLI installed
import csv
import subprocess
from collections import defaultdict
# Mapping of country names to their ISO codes in the CSV
COUNTRIES = {
'Russia': 'RU',
'Singapore': 'SG',