Home Backend Development Python Tutorial Automating Azure Documentation with an AI Assistant

Automating Azure Documentation with an AI Assistant

Oct 25, 2024 am 06:38 AM

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:

  1. Python: As the scripting language as it is commonly installed and widely used.
  2. Azure CLI: To fetch ARM templates from Azure Resource Groups.
  3. OpenAI API Calls: To generate human-readable documentation from ARM templates.
  4. 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:

  1. Get All Resource Groups in the current Azure Subscription.
  2. Uses az CLI to Export ARM Templates from Azure Resource Groups.
  3. We Parse The Templates and send them to an OpenAI compatible API.
  4. 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()
Copy after login
Copy after login

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",
]
Copy after login
Copy after login

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)
Copy after login
Copy after login

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"
Copy after login

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.
Copy after login
  • 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...
Copy after login

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:

  1. 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()
Copy after login
Copy after login
  1. Run the script to generate markdown documentation:
export_command = [
    "az", "group", "export",
    "--name", resource_group_name,
    "--include-parameter-default-value",
    "--output", "json",
]
Copy after login
Copy after login

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)
Copy after login
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1229
24
Python vs. C  : Applications and Use Cases Compared Python vs. C : Applications and Use Cases Compared Apr 12, 2025 am 12:01 AM

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: Games, GUIs, and More Python: Games, GUIs, and More Apr 13, 2025 am 12:14 AM

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.

How Much Python Can You Learn in 2 Hours? How Much Python Can You Learn in 2 Hours? Apr 09, 2025 pm 04:33 PM

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.

The 2-Hour Python Plan: A Realistic Approach The 2-Hour Python Plan: A Realistic Approach Apr 11, 2025 am 12:04 AM

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 vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

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.

Python and Time: Making the Most of Your Study Time Python and Time: Making the Most of Your Study Time Apr 14, 2025 am 12:02 AM

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: Exploring Its Primary Applications Python: Exploring Its Primary Applications Apr 10, 2025 am 09:41 AM

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: Automation, Scripting, and Task Management Python: Automation, Scripting, and Task Management Apr 16, 2025 am 12:14 AM

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.

See all articles