Skip to content

Commit 08fe5ac

Browse files
authored
Feat: azapi - not all resources support tags (#210)
* Feat: azapi - not all resources support tags * fix test * fix tests * fixed some issues based on PR comments
1 parent 1992269 commit 08fe5ac

File tree

10 files changed

+893
-8
lines changed

10 files changed

+893
-8
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ hcl
5050
tf
5151

5252
dist/
53+
54+
venv

azapi/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# azapi
2+
3+
Utility for parsing Microsoft's azapi resource-tag tables, to locate all resources that can be tagged.
4+
For more information check: https://github.com/env0/terratag/issues/209
5+
6+
```bash
7+
python3 -m venv venv
8+
source venv/bin/activate
9+
python install -r ./requirements.txt
10+
python generate.py
11+
```

azapi/generate.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from io import StringIO
2+
from bs4 import BeautifulSoup
3+
import pandas as pd
4+
import re
5+
import requests
6+
7+
url = "https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tag-support"
8+
response = requests.get(url)
9+
html = response.content
10+
11+
soup = BeautifulSoup(html, "html.parser")
12+
13+
tables = soup.find_all("table")
14+
15+
dfs = []
16+
17+
for table in tables:
18+
parent_div = table.find_parent("div", class_="mx-tableFixed")
19+
20+
# Find the h2 within the parent div
21+
title_element = parent_div.find_previous_sibling("h2")
22+
title = title_element.text.strip().lower().replace(" ", "")
23+
24+
df = pd.read_html(StringIO(str(table)))[0]
25+
26+
df["Resource type"] = df["Resource type"].apply(
27+
lambda x: (
28+
f"{title}/{x.lower().replace(' ', '')}"
29+
if title
30+
else x.lower().replace(" ", "")
31+
)
32+
)
33+
34+
dfs.append(df)
35+
36+
df = pd.concat(dfs)
37+
38+
df = df[df["Supports tags"] == "Yes"]
39+
40+
df = df[["Resource type"]]
41+
42+
df.to_csv("azure_resource_tag_support.csv", index=False)

azapi/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
beautifulsoup4==4.12.3
2+
pandas==2.2.3
3+
requests==2.32.3
4+
lxml==5.3.0

0 commit comments

Comments
 (0)