Automating Azure Documentation with an AI Assistant
Managing and documenting Azure Resource Groups (RGs) in large-scale environments can be time-consuming and complicated. But what if you could automate the process of generating documentation that not only explains what resources exist but also how they relate to each other?
In this article, we'll explore how a simple Python script can leverage LLMs (Large Language Models) like OpenAI or Azure OpenAI to automate the creation of comprehensive markdown documentation from ARM templates. What makes this tool powerful is not the use of complex agent frameworks or heavy infrastructure, but pure Python combined with well-established tools like Azure CLI and OpenAI's API. It can even be used with other AI providers, and local LLMs using Ollama or other similar tools.
No Need for Complex Agent Frameworks
A common misconception is that you need elaborate agent frameworks to harness the power of LLMs effectively. In reality, you can achieve powerful, automated workflows using existing tools and simple scripts. In this solution, we combine:
- Python: As the scripting language as it is commonly installed and widely used.
- Azure CLI: To fetch ARM templates from Azure Resource Groups.
- OpenAI API Calls: To generate human-readable documentation from ARM templates.
- Markdown: As the output format for the documentation, which integrates easily into any knowledge base.
The result? A clean, efficient script that creates documentation without needing complicated tooling or AI powered orchestration.
Azure Assistants Source Code
The source code is available in this Github repository: itlackey/azure-assistants. Currently, it contains a single Python script that leverages the Azure CLI and OpenAI API to generate markdown documentation from ARM templates. If there is interest, or I have a need, the repository may be updated with additional tools and scripts to automate other tasks.
How the Script Works
The heart of this tool is the document_resource_groups.py script. It does these four things:
- Get All Resource Groups in the current Azure Subscription.
- Uses az CLI to Export ARM Templates from Azure Resource Groups.
- We Parse The Templates and send them to an OpenAI compatible API.
- The LLM is used to Generate Markdown Documentation that is ready to be included in a knowledge base.
List Resource Groups
The first step is to fetch all resource groups in your Azure Subscription. This is done using the az CLI command from our Python script. We then loop through them to fetch the ARM template.
result = subprocess.run( ["az", "group", "list", "--query", "[].name", "-o", "tsv"], stdout=subprocess.PIPE, text=True, ) resource_groups = result.stdout.splitlines()
Export ARM Templates
Again, using the Azure CLI, the script retrieves the ARM templates for each resource group in the current subscription. These templates contain detailed configuration information for all resources, including their networking and security settings.
export_command = [ "az", "group", "export", "--name", resource_group_name, "--include-parameter-default-value", "--output", "json", ]
Summarizing with LLMs
Next, the script sends the ARM template to OpenAI (or Azure OpenAI) for summarization. Here's where the magic happens. Instead of diving into complex agent workflows, a simple system message and user prompt provide enough context to the LLM to generate insightful documentation.
response = client.chat.completions.create(model=model, messages=messages)
The prompt provides an expected output template and instructs the LLM to:
- List and describe each resource.
- Explain how resources relate to each other.
- Highlight important network configurations.
This allows the LLM to produce structured, easy-to-read documentation without needing any fancy orchestration.
Generating Markdown Documentation
The final step is generating a markdown file that contains the resource group's details. The front matter includes metadata like resource group name, date, and tags. The AI-generated documentation is then added as the content of the document.
front_matter = f"---\n" front_matter += f'title: "{resource_group_name}"\n' front_matter += f"date: {date}\n" front_matter += f"internal: true\n"
Markdown is a universal format, allowing this output to easily integrate into many documentation systems or knowledge management systems.
Customizing the AI Prompts
A key feature of this script is the ability to customize the prompts sent to the LLM. This is where users can fine-tune the type of output they want:
- System Message: Guides the LLM to generate documentation focused on explaining resources, relationships, and networking.
Example:
You are an experienced Azure cloud architect helping to create reference documentation that explains the resources within an Azure Resource Manager (ARM) template. The documentation you create is intended for use in a knowledge base. Your role is to describe the resources in a clear and human-readable way, providing details on the following: - What resources exist in the ARM template. - How the resources relate to each other. - The purpose of each resource (if possible). - Highlighting network configurations and data locations such as storage accounts and databases. - Be sure to include IP addresses in the documentation when they are available. - Include information about virtual network peering. - It is very important that you also include any potential security issues that you may find.
- User Prompt: Dynamically generated based on the resource group being summarized.
Example:
Provide detailed documentation of the following ARM template for resource group: {template_content} The purpose of this documentation is to...
By keeping these prompts flexible and simple, the script avoids over-engineering while still delivering high-quality documentation.
Running the Script
Note: You will need to have az CLI and python3 installed on your machine before you run this script.
Setting up and running the script is straightforward:
- Log into Azure: Ensure you're authenticated with Azure CLI:
result = subprocess.run( ["az", "group", "list", "--query", "[].name", "-o", "tsv"], stdout=subprocess.PIPE, text=True, ) resource_groups = result.stdout.splitlines()
- Run the script to generate markdown documentation:
export_command = [ "az", "group", "export", "--name", resource_group_name, "--include-parameter-default-value", "--output", "json", ]
The script processes each resource group, generates its ARM template, and creates a markdown file in the output directory.
Example Output
Here's an example of what the script generates:
response = client.chat.completions.create(model=model, messages=messages)
This output is concise, readable, and easy to understand - exactly what you need for internal documentation or knowledge base entries.
Conclusion
Azure Assistants is a perfect example of how you can use existing tools and basic Python skills to achieve powerful results with LLMs. There's no need for elaborate agent frameworks when simple scripts, combined with Azure CLI and OpenAI's API, can generate clear, comprehensive documentation for your Azure Resource Groups.
This tool demonstrates that with the right prompts and a solid structure, anyone with basic scripting skills can leverage AI to automate cloud documentation - making it a valuable assistant for any DevOps or infrastructure team.
The above is the detailed content of Automating Azure Documentation with an AI Assistant. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.
