Member-only story
Visualizing Infrastructure as Code with Diagrams by Mingrammer

Infrastructure as Code (IaC) has become a standard practice in cloud and DevOps environments. However, maintaining clear and up-to-date infrastructure diagrams is often overlooked, leading to knowledge gaps and operational inefficiencies. This is where Diagrams by Mingrammer comes in — a Python-based tool that allows engineers to generate infrastructure diagrams programmatically.
What is Diagrams by Mingrammer?
Diagrams is an open-source Python library that enables the visualization of cloud architectures, on-premise infrastructures, and system designs using code. It supports multiple providers such as AWS, Azure, GCP, Kubernetes, and more. Instead of manually drawing infrastructure components, you can define them in Python scripts and generate diagrams automatically.
Why Use Diagrams?
- Automation: Generate infrastructure diagrams dynamically based on IaC configurations.
- Version Control: Store diagrams alongside infrastructure code for better documentation and change tracking.
- Consistency: Maintain uniform and up-to-date architecture visualizations.
- Extensibility: Supports multiple cloud providers and custom icons.
Installation
You can install Diagrams using pip:
apt install python3 python3-pip graphviz -y
pip install diagrams
Creating an Azure Network Diagram
The following example illustrates an Azure Virtual Network with two subnets:
- Subnet 1 contains a Load Balancer and two Virtual Machines.
- Subnet 2 contains an SQL Server instance.
- The Load Balancer distributes traffic between the Virtual Machines.
- Both Virtual Machines communicate with the SQL Server.
from diagrams import Diagram, Cluster
from diagrams.azure.compute import VM
from diagrams.azure.database import SQLServers
from diagrams.azure.network import LoadBalancers, VirtualNetworks
with Diagram("Azure VNet with Subnets", show=False):
with Cluster("Virtual Network"):
with…