Created
June 8, 2020 22:23
-
-
Save lmazuel/e62db4c090e406650d90183c6a840263 to your computer and use it in GitHub Desktop.
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
# Removes RG that start with that prefix | |
import os | |
from azure.common.credentials import ServicePrincipalCredentials | |
from azure.mgmt.resource import ResourceManagementClient | |
RG_PREFIX = "pycog" | |
def get_credentials(): | |
subscription_id = os.environ['AZURE_SUBSCRIPTION_ID'] | |
credentials = ServicePrincipalCredentials( | |
client_id=os.environ['AZURE_CLIENT_ID'], | |
secret=os.environ['AZURE_CLIENT_SECRET'], | |
tenant=os.environ['AZURE_TENANT_ID'] | |
) | |
return credentials, subscription_id | |
def do_it(): | |
credentials, subscription_id = get_credentials() | |
client = ResourceManagementClient(credentials, subscription_id) | |
# List Resource Groups | |
rgs = list(client.resource_groups.list()) | |
for rg in rgs: | |
if rg.name.startswith(RG_PREFIX): | |
print(f"Kill {rg.name}") | |
client.resource_groups.delete(rg.name, polling=False) | |
if __name__ == "__main__": | |
do_it() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment