Output Engine

Terraform Variable Generation

Traverse related graph nodes to generate structured Terraform variable files declaratively.

Terraform Variable Generation

For complex scenarios that require data from multiple related nodes, you can use output templates to traverse the graph and generate structured configuration files like terraform.tfvars.json. This approach keeps your automation logic declarative and version-controlled alongside your infrastructure models.

Let’s generate a complete configuration for the asseteditor application, pulling data from the application node and its related image, network, and server nodes.

Example Output Template (data/output/terraform_asseteditor.toml):

origin_resource = "application"

[[output]]
resource_type = "terraform_variables"
name = "tfvars-for-{{ origin_resource.name }}"
match_on = [
  { property = "name", value = "asseteditor" }
]
template = """
{
  "application_name": "{{ origin_resource.name }}",
  "network": "{{ origin_resource.network[0].name }}",
  "ports": {{ origin_resource.port | json_encode() }},
  "image_details": {
    "name": "{{ origin_resource.image[0].name }}",
    "platform": "{{ origin_resource.image[0].platform[0].name }}"
  },
  "compute_resources": {
    "cores": {{ origin_resource.core }},
    "memory_gb": {{ origin_resource.memory }}
  }
}
"""

After the importer runs, rescile creates a new terraform_variables resource in the graph. You can query its properties, which correspond to the top-level keys of the JSON object generated by the template.

GraphQL Query to Retrieve the Generated tfvars:

query GetAssetEditorTfVars {
  terraform_variables(filter: {name: "tfvars-for-asseteditor"}) {
    application_name
    network
    ports
    image_details
    compute_resources
  }
}