Propagating Data
Using
[[copy_property]]: A “Push” Operation — see also Push vs. Pull Comparison
The [[copy_property]] directive is a declarative “push” operation. It propagates data between resources that are already directly connected. Think of it as property assignment or inheritance: it pushes property values from a source node (origin_resource) to a connected destination node. This is the primary mechanism for ensuring contextual data flows downstream through your graph.
For example, a server resource might need to inherit the environment (prod, dev) from the application it hosts. [[copy_property]] makes this a simple, declarative rule.
It supports several powerful patterns for copying simple properties, entire relations, and extracting data from connected nodes.
How copy_property Works
A [[copy_property]] block defines a rule to copy data from the current origin_resource to connected nodes.
| Key | Mandatory | Description |
|---|---|---|
to |
Yes | The type of the connected destination resource to copy properties to. |
properties |
Yes | An array defining which items to copy. This supports several powerful formats (see below). |
match_on |
No | An array of filter objects. The copy operation only applies if all conditions match on the to (destination) resource. |
properties Array Formats
The properties array is extremely flexible and supports multiple formats for different use cases:
| Format | Example | Description |
|---|---|---|
| Simple Property | "owner" |
Copies the owner property from the source to the destination with the same name. |
| Relation Copy | "network" |
If network is a known resource type, this copies the entire relationship from the source to the destination. For example, if (app)-[network]->(net-1), this creates (server)-[network]->(net-1). This can be used to propagate a relation from a property or a parameter. |
| Extract from Relation (Implicit Name) | "network.name" |
Extracts the name property from the related network resource. The new property on the destination is named after the relation (network). |
| Rename Property | { from = "owner", as = "server_owner" } |
Copies the owner property from the source but renames it to server_owner on the destination. |
| Extract from Relation (Explicit Name) | { from = "network.name", as = "domain" } |
Extracts the name property from the related network resource and saves it to a new property explicitly named domain. |
| Transform with Template | { from="v", as="major", template="..."} |
Copies the v property but transforms its value using a Tera template. The original value is available as {{ value }}. |
Comprehensive Example
Goal: For every application, find its connected server resources. If a server is marked as critical, propagate a rich set of data from the application and its related region to the server.
# In a model with origin_resource = "application"
origin_resource = "application"
[[copy_property]]
# 1. Define the destination resource type.
to = "server"
# 2. Conditionally apply this rule only to critical servers.
match_on = [ { property = "status", value = "critical" } ]
# 3. Define the properties to copy using various formats.
properties = [
# Simple property copy
"environment",
# Rename a property
{ from = "owner", as = "server_owner" },
# Copy the entire 'network' relation from the application to the server
"network",
# Extract the 'name' from the related 'region', create a 'region' property on the server
"region.name",
# Extract 'name' from 'region', but create an explicitly named 'server_region' property
{ from = "region.name", as = "server_region" },
# Transform a property value using a template
{ from = "version", as = "major_version", template = "{{ value | split(pat='.') | first }}" }
]
Graph Impact:
Consider an application with owner: "team-a", version: "2.7.1", a relation (app)-[network]->(net-prod), and a relation (app)-[region]->(region {name: "eu-central-1"}). If this app is connected to a server with status: "critical", the server will be updated with the following properties and relations:
- An
environmentproperty copied directly from the application. - A new property
server_owner: "team-a". - A new relation
(server)-[network]->(net-prod). - A new property
region: "eu-central-1". - A new property
server_region: "eu-central-1". - A new property
major_version: "2".
Property Prefixes in copy_property
The destination property name—whether it’s the simple property string, the as value, or the relation name when extracting from a relation (e.g., network from network.name)—supports special prefixes that mirror their behavior in [[create_resource]]:
_: A property name prefixed with an underscore (e.g.,_owneror{ from = "...", as = "_owner" }) will be created on the destination asowner, but it will be excluded from the automatic relationship creation phase.~: A property name prefixed with a tilde (e.g.,~version) forces the final copied value to be stored as a string, regardless of its original data type (e.g., a number2becomes a string"2").- These prefixes can be combined (e.g.,
_~version). The importer processes prefixes from left to right.