Using expr
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
Further Reading
For more advanced usage, see the official expr documentation or try out expressions in the playground above.
Last updated
Was this helpful?

