-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
1992269
commit 08fe5ac
Showing
10 changed files
with
893 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,5 @@ hcl | |
tf | ||
|
||
dist/ | ||
|
||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# azapi | ||
|
||
Utility for parsing Microsoft's azapi resource-tag tables, to locate all resources that can be tagged. | ||
For more information check: https://github.com/env0/terratag/issues/209 | ||
|
||
```bash | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
python install -r ./requirements.txt | ||
python generate.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from io import StringIO | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.