structurizr / dsl

Structurizr DSL
https://docs.structurizr.com/dsl
Apache License 2.0
1.41k stars 266 forks source link

Error when creating a deployment relationship inside the definition of a node #165

Closed deinspanjer closed 1 year ago

deinspanjer commented 1 year ago

I’ve hit something that feels like a bug to me. If I try to make a forward or backward relationship inside a container instance or an infrastructure node, I get a syntax error saying the far-end node doesn’t exist. However, if I put the relationship outside the creation, it works fine. The docs say that both containerInstance and infrastructureNode blocks allow relationships as children, so I’m not sure what’s going on exactly. Here is an example DSL that demonstrates the problem. You can flip the commented lines to see it work properly.

workspace {
    !identifiers hierarchical

    model {
        staff = person "Staff"
        user = person "User"
        app = softwareSystem "Software System" {
            webapp = container "Web Application" {
                user -> this "updates details
            }
            backend = container "Backend server" {
                webapp -> this "makes requests to"
            }
            mgmt = container "Management Page" {
                -> backend "makes requests to"
                staff -> this "manages app
            }
        }

        prod = deploymentEnvironment "Production Access" {

            dc = deploymentNode "Datacenter" {
                api = infrastructureNode "API Gateway"
                vpn = infrastructureNode "VPN Gateway" {
                    // This statement doesn't work
                    // staff.vpn -> this "establishes secure tunnel"
                }
                server = deploymentNode "Backend Server" {
                    backend = containerInstance app.backend
                }
            }

            staff = deploymentNode "Staff PC" {
                browser = deploymentNode "Web Browser" {
                    mgmt = containerInstance app.mgmt {
                        // This statement doesn't work either
                        // -> dc.api "routes through"
                    }
                }
                vpn = infrastructureNode "VPN Client"
            }
            user = deploymentNode "User PC" {
                browser = deploymentNode "Web Browser" {
                    webapp = containerInstance app.webapp
                }
            }

            // But these do
            staff.vpn -> dc.vpn "establishes secure tunnel"
            staff.browser.mgmt -> dc.api "routes request through"
        }
    }
}
simonbrowndotje commented 1 year ago

There are two problems here:

  1. You're trying to reference staff before it's been created (as always, order is important with the DSL).
  2. You're using hierarchical identifiers, and I think the DSL parser is trying to find an element named staff.vpn inside the deployment node dc, which doesn't exist. prod.staff.vpn will work though.
deinspanjer commented 1 year ago

Urgh. that first issue was purely a mistake on my part. My original example had staff at the top and the problem was the same.

I think your second point is the source of my issue. I thought that it would look for items that were at the top level of the environment. I should have tested referencing the environment itself. :/