Using expr
Use the expr expression language in bricks.json for dynamic configuration, conditional logic, string operations, and runtime property references
Bluebricks leverages the expr expression language to enable dynamic configurations within your bricks.json files. This allows for powerful manipulations, conditional logic, and more.
What is expr?
expr is a lightweight, high-performance expression language for Go, designed for dynamic evaluation of expressions. In Bluebricks, it lets you:
Perform arithmetic and string operations
Use conditional logic (if/else, ternary)
Access built-in functions for manipulating strings, lists, maps, etc.
Reference properties, data, and secrets dynamically
Common Use Cases
Basic arithmetic and string operations: Concatenation, addition, subtraction, etc.
Conditional expressions: Ternary operators or if/else logic.
Functions: Built-in functions for manipulating strings, lists, maps, etc.
Examples
1. Concatenating strings and using current time
{
"packages": [
{
"name": "my_s3_bucket",
"version": "1.0.0",
"props": {
"bucket_name": {
"value": "now().Format('02012006030405')+'_sample_bucket'+(Props.vpc_id ?? Data.vpc1.vpc_id)"
}
}
}
]
}now().Format('02012006030405')generates a timestamp string.'_sample_bucket'is a static string.(Props.vpc_id ?? Data.vpc1.vpc_id)uses the null coalescing operator: it will useProps.vpc_idif defined, otherwiseData.vpc1.vpc_id.
2. Conditional Logic (Ternary Operator)
This sets instance_type to m5.xlarge if Props.environment is prod, otherwise t3.medium.
3. Accessing nested properties and list elements
4. Null coalescing for fallbacks
Use the ?? operator to provide fallback values:
Props.vpc_id ?? Data.shared_vpc.vpc_id uses Props.vpc_id if defined, otherwise falls back to Data.shared_vpc.vpc_id.
5. String concatenation
Build complex strings from multiple sources:
6. Mathematical operations
Perform calculations for resource sizing:
7. Complex conditional logic
Combine multiple conditions:
8. Output aggregation with expressions
Combine outputs from multiple packages:
Best practices
Use expressions for dynamic values, not static ones
Keep expressions readable; avoid deeply nested ternaries
Use null coalescing (
??) for safe fallbacksTest complex expressions with different input combinations
Further reading
Blueprint Composition Patterns: architectural patterns that use expressions in context
Last updated

