Skip to content

Instantly share code, notes, and snippets.

@smereczynski
Last active May 25, 2018 19:47
Show Gist options
  • Select an option

  • Save smereczynski/2bfcac4532c6b0c3576d9b54946d2761 to your computer and use it in GitHub Desktop.

Select an option

Save smereczynski/2bfcac4532c6b0c3576d9b54946d2761 to your computer and use it in GitHub Desktop.
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource import ResourceManagementClient
import os
import keyring.backend
from keyrings.alt.file import PlaintextKeyring
keyring.set_keyring(PlaintextKeyring())
TENANT_ID = os.getenv('TENANT_ID')
CLIENT = os.getenv('CLIENT')
KEY = os.getenv('KEY')
SUBSCRIPTION = os.getenv('SUBSCRIPTION')
credentials = ServicePrincipalCredentials(
client_id=CLIENT,
secret=KEY,
tenant=TENANT_ID
)
client = ResourceManagementClient(credentials, SUBSCRIPTION)
rgs = client.resource_groups.list()
for rg in rgs:
print(rg.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment