Skip to content

Instantly share code, notes, and snippets.

@ronniejoshua
Created June 11, 2021 08:09
Show Gist options
  • Save ronniejoshua/02cf265685a86b5c4b3751c7baa89099 to your computer and use it in GitHub Desktop.
Save ronniejoshua/02cf265685a86b5c4b3751c7baa89099 to your computer and use it in GitHub Desktop.
Python code to whitelist External IP for GCP Compute Engine Firewall Rules
import requests
import os
def gcp_firewall_ip_whitelisting():
my_external_ip = requests.get("https://api.ipify.org").text
print(f"My External IP Address: {my_external_ip}")
known_ip_addresses = ""
cmd_to_run = f"gcloud compute firewall-rules update nc-de-doc-sec --source-ranges {my_external_ip}, {known_ip_addresses}"
os.system(cmd_to_run)
if __name__ == "__main__":
gcp_firewall_ip_whitelisting()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment