Architectural Models

Pulling Data During Creation

How to use copy_from in [[create_resource]] to pull properties from a related resource at creation time.

Pulling Data During Creation (copy_from)

Copying Properties from Related Resources at Creation Time

While [create_resource.properties] sets properties based on the origin_resource, the copy_from directive provides a declarative “pull” mechanism to copy properties from a different, related resource at the moment of creation.

This avoids deep Tera path traversals like {{ origin_resource.datacenter[0].region_code }} for multiple properties, replacing them with a single, readable declaration.

Syntax

[[create_resource]]
resource_type = "server"
relation_type = "RUNS"
name = "server_{{ origin_resource.name }}"
copy_from = { property = "datacenter", properties = [
  "region_code",
  { from = "provider", as = "cloud_provider" }
] }
Key Description
property The property on the origin_resource whose value is the name of the resource to copy from.
properties An array of property descriptors. Supports the same formats as [[copy_property]].

Example

Goal: When creating a server for an application, copy region_code and cloud_provider from the datacenter resource that the application belongs to.

origin_resource = "application"

[[create_resource]]
resource_type = "server"
relation_type = "RUNS"
name = "server_{{ origin_resource.name }}"
copy_from = { property = "datacenter", properties = [
  "region_code",
  { from = "provider", as = "cloud_provider" }
] }

Logic:

  1. For each application, read its datacenter property value (e.g., "dc-frankfurt").
  2. Find the datacenter resource named "dc-frankfurt".
  3. Copy its region_code property to the new server with the same name.
  4. Copy its provider property to the new server, renaming it to cloud_provider.

Comparison with Tera Traversal

Approach Code
Tera path region_code = "{{ origin_resource.datacenter[0].region_code }}"
copy_from copy_from = { property = "datacenter", properties = ["region_code"] }

copy_from is more readable when copying several properties from the same related resource and communicates intent more clearly than repeated Tera traversals.

For propagating data across resources that are already connected, see [[copy_property]] Reference.