mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
37.55k stars 2.45k forks source link

Adjustments of clusters #346

Open Olgoetz opened 4 years ago

Olgoetz commented 4 years ago

Hi,

First of all, thanks a lot for this tool. I really like it a lot. At the momen, I am struggling with a proper alignment of nodes:

from diagrams.aws.compute import ECS, EKS, Lambda, EC2, AutoScaling
from diagrams.aws.database import RDS
from diagrams.aws.storage import S3
from diagrams.aws.network import ELB, InternetGateway

with Diagram("Terraform Enterprise", show=True):

    with Cluster("AWS Cloud"):
        source = ELB("Application Load Balancer")
        with Cluster("Availability Zone 1"):
            with Cluster("Private Subnet"): 
                tfe_1 = EC2("Terraform Enterprise")
                rds_1= RDS("Postgre Main")

            with Cluster("Public Subnet"):
                squid_1 = EC2("Squid Proxy")

        with Cluster("Availability Zone 2"):

            with Cluster("Public Subnet"):
                squid_2 = EC2("Squid Proxy")

            with Cluster("Private Subnet"):
                rds_2= RDS("Postgre Standby")
                tfe_2 = EC2("Terraform Enterprise")

        source >> [tfe_1, tfe_2]
        tfe_1 >> squid_1
        tfe_2 >> squid_2
        [squid_1, squid_2] >> InternetGateway("IGW")

The result is:

terraform_enterprise

By chaning the position of the RDS nodes, it should be fine. But I do not know how?

clayms commented 4 years ago

The best I could do is use a blank Cluster as a spacer.

However, with the current code base, the background colors of the Clusters are set automatically based on their nested depth so there is no way to make the spacer-Cluster completely invisible without changing the code.

https://github.com/mingrammer/diagrams/blob/e9f5617c2ab3963b849f4c60f3d97cfce938bbd2/diagrams/__init__.py#L242toL245

from diagrams import Cluster, Diagram
from diagrams.aws.compute import ECS, EKS, Lambda, EC2, AutoScaling
from diagrams.aws.database import RDS
from diagrams.aws.storage import S3
from diagrams.aws.network import ELB, InternetGateway
from diagrams.custom import Custom

with Diagram("Terraform Enterprise", show=False) as diag:

    with Cluster("AWS Cloud"):

        with Cluster("Availability\nZone 1"):
            with Cluster("Public Subnet"):
                squid_1 = EC2("Squid Proxy")

            with Cluster("Private Subnet"): 
                rds_1= RDS("Postgre\nMain")
                tfe_1 = EC2("Terraform\nEnterprise")
                tfe_1 >> squid_1

            with Cluster(""): 
                rds_1 - Edge(penwidth="0.0") - Custom("","transparent.png")                

        with Cluster("Availability\nZone 2"):
            with Cluster("Private\nSubnet"):
                tfe_2 = EC2("Terraform \nEnterprise")
                rds_2= RDS("Postgre\nStandby")

            with Cluster(""): 
                rds_2 - Edge(penwidth="0.0") - Custom("","transparent.png")   

            with Cluster("Public Subnet"):
                squid_2 = EC2("Squid Proxy")
                tfe_2 >> squid_2

    [squid_1, squid_2] >> InternetGateway("IGW")
    source = ELB("Application\nLoad\nBalancer")
    source >> [tfe_1, tfe_2]

diag

image

clayms commented 4 years ago

Slight modification of above to merge the blank Cluster with the "Public Subnet" Cluster.

with Diagram("Terraform Enterprise", show=False) as diag:

    with Cluster("AWS Cloud"):

        with Cluster("Availability\nZone 1"):
            with Cluster("Private Subnet"): 
                rds_1 = RDS("Postgre\nMain")
                tfe_1 = EC2("Terraform\nEnterprise")

            with Cluster("Public Subnet"):
                rds_1 - Edge(penwidth="0.0") - Custom("","transparent.png")
                squid_1 = EC2("Squid Proxy")
                tfe_1 >> squid_1

        with Cluster("Availability\nZone 2"):
            with Cluster("Private\nSubnet"):
                tfe_2 = EC2("Terraform \nEnterprise")
                rds_2= RDS("Postgre\nStandby")

            with Cluster("Public Subnet"):
                squid_2 = EC2("Squid Proxy")
                tfe_2 >> squid_2
                rds_2 - Edge(penwidth="0.0") - Custom("","transparent.png")

    [squid_1, squid_2] >> InternetGateway("IGW")
    source = ELB("Application\nLoad\nBalancer")
    source >> [tfe_1, tfe_2]

diag

image