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:
- For each
application, read itsdatacenterproperty value (e.g.,"dc-frankfurt"). - Find the
datacenterresource named"dc-frankfurt". - Copy its
region_codeproperty to the newserverwith the same name. - Copy its
providerproperty to the newserver, renaming it tocloud_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.