Infrastructure Diagrams as Code
Tags: terraform, architecture, python, cloud
Published: 2022-08-21 16:13:00

Diagrams are playing one of the major role in software development, Architecture development and Cloud infrastructure building.

This python package diagrams is really helpful to Software architect, Solutions architect, Cloud engineers and Enterprise architect to keep our infrastructure diagram as code 

**Benefits**

- Easy to understand
- Help to simplify the process
- Proper documentation
- Versioning our infrastructure diagrams changes as code
- Easy to customise
- Open source


It's currently supports main major providers including: **AWS, Azure, GCP, Kubernetes, Alibaba Cloud, Oracle Cloud** etc... It also supports **On-Premise** nodes, **SaaS** and major Programming frameworks and languages


###Installation

It requires **python 3.6** version or heigher version python package

```

#using pip (pip3)
$ pip install diagrams

```

### Quick start

```

# SampleDiagram.py

from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB

#create diagram
with Diagram("Web Service", show=False):
    ELB("lb") >> EC2("web") >> RDS("userdb")



to run the above code in your terminal


```
```
$ python SampleDiagram.py

```


output


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3azyswrkgi1po1wc1ppu.png)


### Example Clustered web service Infrastructure

```

#ClusterWebService.py

from diagrams import Cluster, Diagram
from diagrams.aws.compute import ECS, Lambda
from diagrams.aws.database import ElastiCache, RDS
from diagrams.aws.network import ELB, Route53
from diagrams.aws.integration import SQS
from diagrams.aws.storage import S3

#create diagram
with Diagram("Clustered Web Services", show=False):
    # route53  
    dns = Route53("dns")

    #Elastic load balancer
    lb = ELB("App load balancer")

    #Elastic containe service cluster
    with Cluster("Services"):
        svc_group = [ECS("service1"),
                     ECS("service2"),
                     ECS("service3")]

    #Simple queue service
    queue = SQS("SQS service")

    #Relational Database service db cluster
    with Cluster("RDS DB Cluster"):
        db_primary = RDS("userdb")
        db_primary - [RDS("backup")]

    #lambda functions cluster
    with Cluster("Lambdas"):
      handlers = [
          Lambda('Lambda 1'),
          Lambda('Lambda 2'),
          Lambda('Lambda 3'),
      ]

    #Elasticcache service
    memcached = ElastiCache("memcached")

    # S3 serive
    store = S3("File storage")

    #architecture work flow
    dns >> lb >> svc_group >> queue >> handlers
    handlers[0] >> memcached
    handlers[1] >> store
    handlers[2] >> db_primary

```



to run the code

```
$ python ClusterWebService.py

```

output


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23tbclxogap1kkhqm3l8.png)


- Link to library [diagrams](https://diagrams.mingrammer.com/)
- Github link : [Click here](https://github.com/mingrammer/diagrams)

Follow [Cloudnloud tech community](https://www.linkedin.com/company/cloudnloud/) to know more Linux,Cloud,DevOps,Docker,K8s,Seccurity,Solutions,Re-Engineering,Virtuvalization,Data,AI,Python,Ansible,Terraform information


**Keep Learning Keep Growing !!!**

### Community and Social Footprints :

- [Veerasolaiyappan](https://www.linkedin.com/in/veera26/)
- [GitHub](https://github.com/cloudnloud)
- [Twitter](https://twitter.com/cloudnloud)
- [YouTube Cloud DevOps Free Trainings](https://www.youtube.com/c/CloudnLoud)
- [Linkedin Page](https://www.linkedin.com/company/cloudnloud/)
- [Linkedin Group](https://www.linkedin.com/groups/9124202/)
- [Discord Channel](https://discord.com/invite/vbjRQGVhuF)
- [Dev](https://dev.to/cloudnloud)