Skip to content

Commit 433f191

Browse files
authored
Create getResources.py
1 parent d8d7726 commit 433f191

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

aws/getResources.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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}")

0 commit comments

Comments
 (0)