QUERY ACROSS NAMESPACES
This guide shows you how to read data from other namespaces in a shared datastore using CEL expressions.
Prerequisites
- A repository with a namespace assigned (
swamp datastore namespace set) - At least one other namespace in the shared datastore with data to query
Point lookups with namespace prefix
To read data from a specific namespace, prefix the model name with the namespace and a colon:
globalArguments:
vpc_id: "${{ data.latest('infra:my-vpc', 'result').attributes.vpcId }}"This reads the latest result from the my-vpc model in the infra namespace,
regardless of which namespace the current repository belongs to.
Without a prefix, point lookups scope to the current namespace:
globalArguments:
local_result: "${{ data.latest('my-model', 'result').attributes.status }}"Wildcard lookups
If you know the model name but not which namespace it belongs to, use *:
globalArguments:
result: "${{ data.latest('*:my-vpc', 'result').attributes.vpcId }}"The wildcard searches all namespaces. If the model name exists in more than one namespace, the lookup fails with an ambiguity error. Use an explicit namespace prefix to resolve the ambiguity.
Query with namespace predicates
data.query() returns results from all namespaces by default. To filter by
namespace, use the ns field in the predicate:
globalArguments:
infra_models: "${{ data.query('ns == \"infra\"') }}"Combine ns with other predicates:
globalArguments:
infra_vpcs: "${{ data.query('ns == \"infra\" && modelName == \"my-vpc\"') }}"The field name is ns, not namespace. Refer to the
CEL Expressions reference for the full list
of query fields.
Use cross-namespace data in model definitions
A common pattern: one namespace produces infrastructure data, another consumes it.
# In the "compute" namespace — references infra namespace data
type: "@swamp/aws/ec2/instance"
name: web-server
globalArguments:
subnetId: "${{ data.latest('infra:networking', 'result').attributes.subnetId }}"
securityGroupId: "${{ data.latest('infra:networking', 'result').attributes.sgId }}"Use cross-namespace data in workflows
Workflow step inputs support the same CEL syntax:
jobs:
deploy:
steps:
- name: launch-instance
model: web-server
method: create
task:
inputs:
ami: "${{ data.latest('infra:base-ami', 'result').attributes.imageId }}"