Variable Interpolation
Variables within variables
Introduction
Oftentimes, you will need to define variables whose values depend on other variables. To do this, you can use Value interpolation.
Starting with some examples always works best in these cases.
Some Examples
-
An environment variable identifier containing a complete identifier for your Bunnyshell environment.
{{ project.name }} : {{ org.name }} : {{ env.name }} -
A variable that is using the identifier variable to create a logging content prefix.
{{ "now"|date("m/d/Y") }} {{ env.var.identifier|lower }} -
A variable that interpolates a conditional value
{% if env.type == 'ephemeral' %}true{% else %}false{% endif %}
Where to use value interpolation
- Template variables
- Variables (at Project, Environment, or Component level)
- Environment variables groups
- Docker-compose Components or DockerImage Components
- Build arguments
- Build secrets
- Build context
- Build Dockerfile
- Build target
- CustomDockerImage Components
- runnerImage
- runnerImageAuth.username and .password
- build commands
- environment variables
- Static applications
- build command
- build arguments
- build secrets
- Helm Components, Kubernetes Manifest Components, Terraform Components or Generic Components
- runnerImage
- environment variables
- deploy, destroy, start and stop commands
- Docker-compose Components
- dockerCompose.image
- environment variables
- pod.init_containers[].environment
- pod.sidecar_containers[].environment
- hosts[].hostname
- hosts[].path
- hosts[].externalAddress
- hosts[].k8s.ingress.className
- hosts[].k8s.ingress.annotations values
- files
- cronJobs[].command
- hpa.metrics[].matchLabels
- hpa.metrics[].describedObject.apiVersion, .kind and .name
- Remote dev
- kubernetes resource name
- kubernetes resource namespace
- container command
- container environment
Available interpolation values
- Organization variables
org.nameorg.unique
- Project variables
project.name
- Template variables
template.vars.VAR_NAME
- Environment variables
env.uniqueenv.nameenv.type - primary / ephemeralenv.base_domainenv.urlHandleenv.k8s.namespaceenv.k8s.version(Kube version of the environment deploy cluster, e.g.1.33)env.vars.NAME
- Environment variables groups
env.varGroups.GROUP_NAMEenv.varGroups.GROUP_NAME.VAR_NAME
- Environment deploy cluster
env.cluster.displayNameenv.cluster.nameenv.cluster.cloud(aws,azure,gcp, ...)
- Components variables
components.COMPONENT_NAME.namecomponents.COMPONENT_NAME.gitBranchcomponents.COMPONENT_NAME.gitBranchSha2components.COMPONENT_NAME.ingress.hosts[*]components.COMPONENT_NAME.ingress.hosts[*].urlcomponents.COMPONENT_NAME.ingress.hosts[*].hostnamecomponents.COMPONENT_NAME.ingress.hosts[*].pathThe*must be replaced with the index, eg.0for the first host listed under thehostsattribute,1for the second host and so on.components.COMPONENT_NAME.vars.NAMEcomponents.COMPONENT_NAME.image1components.COMPONENT_NAME.imageName1components.COMPONENT_NAME.imageTag1components.COMPONENT_NAME.exported.VAR_NAME(only for Helm, Kubernetes, Terraform and Generic components)\
Inside a component definition you can use directly
component.*instead ofcomponents.COMPONENT_NAME.*whereCOMPONENT_NAMEis the current component name. This is also shorter to write, and very handy in case you will rename the component and you want some values to be strictly tied to component name, likehost.hostname='{{ component.name }}-{{ env.base_domain }}'
- Component containers variables
components.COMPONENT_NAME.containers.CONTAINER_NAME.vars.VAR_NAME
1 Helm, Kubernetes Manifest and Terraform components don’t have these. Generic component has these only when they have set .dockerCompose.build or .dockerCompose.image
2 gitBranchSha is computed at the beginning of the deploy for the components involved in the deploy, so it may be empty or outdated in other contexts.
Updated 20 days ago
