Skip to content

Instantly share code, notes, and snippets.

@siennathesane
Created September 18, 2017 19:45
Show Gist options
  • Save siennathesane/1d74ef584675c9820f3268de0f74f00a to your computer and use it in GitHub Desktop.
Save siennathesane/1d74ef584675c9820f3268de0f74f00a to your computer and use it in GitHub Desktop.
Get a list of all Azure Regions for your Subscription.
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.resource.subscriptions import SubscriptionClient
from json import dumps
import os
def get_azure_regions():
client = SubscriptionClient(credential_loader())
locations = client.subscriptions.list_locations(os.getenv("AZURE_SUBSCRIPTION_ID"))
regions = {}
for x in locations:
regions[x.display_name] = x.name
print(dumps(regions))
def credential_loader():
return ServicePrincipalCredentials(
client_id=os.getenv("AZURE_CLIENT_ID"),
secret=os.getenv("AZURE_CLIENT_SECRET"),
tenant=os.getenv("AZURE_TENANT_ID")
)
def main():
get_azure_regions()
if __name__ == "__main__":
main()
@siennathesane
Copy link
Author

siennathesane commented Sep 18, 2017

As of Sept 18th, 2017:

{
	"East US 2": "eastus2",
	"Central India": "centralindia",
	"Central US": "centralus",
	"West US": "westus",
	"UK South": "uksouth",
	"South India": "southindia",
	"Korea Central": "koreacentral",
	"Korea South": "koreasouth",
	"South Central US": "southcentralus",
	"East US": "eastus",
	"Brazil South": "brazilsouth",
	"Canada Central": "canadacentral",
	"North Central US": "northcentralus",
	"West Europe": "westeurope",
	"Canada East": "canadaeast",
	"West India": "westindia",
	"Japan West": "japanwest",
	"East Asia": "eastasia",
	"Southeast Asia": "southeastasia",
	"Australia Southeast": "australiasoutheast",
	"Australia East": "australiaeast",
	"West US 2": "westus2",
	"North Europe": "northeurope",
	"UK West": "ukwest",
	"Japan East": "japaneast",
	"West Central US": "westcentralus"
}

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