Variables
Variables
Since hulk templates are environment agnostic, by default it is hard to define behaviour that is different between stages.
Letβs say I would like my custom domain value to be different in staging vs prod, this, based on what we learned so far would not be possible.
This is where variables come in! They are optionally defined inside the variables key of each file (main or module), and are only scoped to the current file. This design choice was made to make sure
variables help achieve edge cases where the standard definition is not enough. We want the definition to remain atomic and not become variable references to variables everywhere across files.
Usage
To use variables, we use the symbol {VAR_NAME} where VAR_NAME is the value of the key you want to use.
You will also see this pattern {env} used across resource names. This is a reserved variable that will contain the value of the environment at runtime. Feel free to use it where you need this value (whether it is in names, app settings, etc).
Limitations
Variables are restricted to string, integers and boolean values, you cannot define other types such as arrays and objects as variables
Example
Here is an example defining a frontdoor endpoint using variables for the custom domain:
{
"variables": {
"custom-domain": {
"prod": "https://api.my-domain.com"
"staging": "https://api-staging.my-domain.com"
}
},
"resources": [
{
"frontdoor": {
"name": "fd-example-{env}",
"sku": "Standard",
"endpoints": [
{
"name": "func-myapp-{env}",
"routes": [
{
"name": "default-route",
"origin_path": "/",
"patterns": ["/*"],
"@origin_group_name": "func-myapp-{env}",
"@rule_set_names": ["defaultruleset"],
"@custom_domains": [
"{custom-domain}"
]
}
]
}
],
"origin_groups": [
{
"name": "func-myapp-{env}",
"origins": [
{
"name": "func-myapp-{env}",
"type": "FunctionApp",
"@function_app_name": "func-myapp-{env}"
}
]
}
],
"rule_sets": [
{
"name": "defaultruleset",
"rules": []
}
],
"custom_domains": [
{
"type": "External",
"name": "{custom-domain}"
}
]
}
}
]
}
Here the variable will be replaced at runtime with the proper value before transpilation to Bicep.