Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: azapi - not all resources support tags #210

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ hcl
tf

dist/

venv
eranelbaz marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 10 additions & 0 deletions azapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# azapi

Utility for parsing Microsoft's azapi resource-tag tables, to locate all resources that can be tagged.
eranelbaz marked this conversation as resolved.
Show resolved Hide resolved

```bash
python3 -m venv venv
source venv/bin/activate
python install -r ./requirements.txt
python generate.py
```
42 changes: 42 additions & 0 deletions azapi/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from io import StringIO
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the utility for parsing the html file and building the white list.

from bs4 import BeautifulSoup
import pandas as pd
import re
import requests

url = "https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tag-support"
response = requests.get(url)
html = response.content

soup = BeautifulSoup(html, "html.parser")

tables = soup.find_all("table")

dfs = []

for table in tables:
parent_div = table.find_parent("div", class_="mx-tableFixed")

# Find the h2 within the parent div
title_element = parent_div.find_previous_sibling("h2")
title = title_element.text.strip().lower().replace(" ", "")

df = pd.read_html(StringIO(str(table)))[0]

df["Resource type"] = df["Resource type"].apply(
lambda x: (
f"{title}/{x.lower().replace(' ', '')}"
if title
else x.lower().replace(" ", "")
)
)

dfs.append(df)

df = pd.concat(dfs)

df = df[df["Supports tags"] == "Yes"]

df = df[["Resource type"]]

df.to_csv("azure_resource_tag_support.csv", index=False)
eranelbaz marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions azapi/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
beautifulsoup4==4.12.3
pandas==2.2.3
requests==2.32.3
lxml==5.3.0
Loading