Using Tera Templates
This example generates a new service_summary resource for every application that is on the edge network. Each summary is made available as a downloadable JSON file.
data/output/service_summary.toml
origin_resource = "application"
# Define some static data available to the template
output_metadata = { version = "1.1", author = "security-team" }
[[output]]
resource_type = "service_summary"
name = "summary-for-{{ origin_resource.name }}"
filename = "summary-{{ origin_resource.name }}.json"
mimetype = "application/json"
match_on = [
{ property = "network_zone", value = "edge" }
]
# The template uses Tera to generate a JSON object, including conditional logic.
# All variables from the context (`origin_resource`, `output_metadata`) are available.
template = '''
{
"output_author": "{{ output_metadata.author }}",
"application_name": "{{ origin_resource.name }}",
"owner": "{{ origin_resource.has_responsibility[0].node.name }}",
"hosting_details": {
"platform": "{{ origin_resource.runs_on[0].node.name }}",
"criticality": "{% if origin_resource.environment == 'prod' %}"high"{% else %}"low"{% endif %}"
}
}
'''
- Graph Impact:
-
The importer finds all
applicationresources that match thematch_oncriteria (e.g.,app-1andapp-2). -
It creates a single new resource of type
service_summary. This resource’s primary key (name) is also set toservice_summary. -
For each matching
application(app-1,app-2): a. It renders thenametemplate to get the primary key for a new resource (e.g.,summary-for-app-1). b. It renders thetemplate, which produces a JSON object string. c. It parses this JSON string. d. It creates a new resource of typeservice_summarywith the generated name. The keys and values from the parsed JSON become the properties of this new resource. -
For
app-1, a newservice_summaryresource is created with properties like:{ "name": "summary-for-app-1", "filename": "summary-app-1.json", "mimetype": "application/json", "output_author": "security-team", "application_name": "app-1", "owner": "team-alpha", "hosting_details": { ... } } -
A similar resource is created for
app-2. -
Finally, a
DESCRIBED_BYrelationship is created from each matchingapplication(app-1,app-2) to its corresponding newservice_summaryresource.
-