File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Import the needed credential and management objects from the libraries.
2
+ from azure .identity import AzureCliCredential
3
+ from azure .mgmt .resource import ResourceManagementClient
4
+ import os
5
+
6
+ # Acquire a credential object using CLI-based authentication.
7
+ credential = AzureCliCredential ()
8
+
9
+ # Retrieve subscription ID from environment variable.
10
+ subscription_id = os .environ ["AZURE_SUBSCRIPTION_ID" ]
11
+
12
+ # Obtain the management object for resources.
13
+ resource_client = ResourceManagementClient (credential , subscription_id )
14
+
15
+ # Retrieve the list of resource groups
16
+ group_list = resource_client .resource_groups .list ()
17
+
18
+ # Show the groups in formatted output
19
+ column_width = 40
20
+
21
+ print ("Resource Group" .ljust (column_width ) + "Location" )
22
+ print ("-" * (column_width * 2 ))
23
+
24
+ for group in list (group_list ):
25
+ print (f"{ group .name :<{column_width }} { group .location } " )
You can’t perform that action at this time.
0 commit comments