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)
{
"props": {
"environment": {
"type": "string",
"default": "dev"
}
},
"packages": [
{
"name": "my_instance",
"version": "1.0.0",
"props": {
"instance_type": {
"value": "Props.environment == 'prod' ? 'm5.xlarge' : 't3.medium'"
}
}
]
}This sets instance_type to m5.xlarge if Props.environment is prod, otherwise t3.medium.
3. Accessing nested properties and list elements
{
"props": {
"network_config": {
"type": "object",
"default": {
"subnets": ["subnet-abc", "subnet-def"],
"security_groups": ["sg-123"]
}
}
},
"packages": [
{
"name": "my_service",
"version": "1.0.0",
"props": {
"subnet_id": { "value": "Props.network_config.subnets[0]" },
"security_group_id": { "value": "Props.network_config.security_groups[0]" }
}
}
]
}Further Reading
For more advanced usage, see the official expr documentation or try out expressions in the playground above.
Last updated
Was this helpful?

