Skip to content
Skip to Content

References

Build a variable's value from a shared variable or from another service's, with ${{shared.NAME}} and ${{service.NAME}}, worked out at each deploy.

A variable's value can refer to other variables. OpenPanel works the references out at each deploy, so a value you change in one place reaches every service that refers to it at its next deploy.

The two forms

ReferenceIs replaced by
${{shared.NAME}}NAME as set on the project or on the service's environment; the environment's wins.
${{api.NAME}}NAME as the service called api, in the same environment, gets it: its own variables over the shared ones.

A reference can sit anywhere in a value, as often as you need:

openpanel env set API_URL='http://${{api.HOST}}:${{api.PORT}}' --project shop --service web
openpanel env set LEVEL='${{shared.LOG_LEVEL}}' --project shop --service web

Put the value in single quotes in your shell, so the shell leaves ${{…}} alone. Spaces inside the braces are allowed: ${{ shared.LOG_LEVEL }} works too.

Through the API, the value is sent as it is:

curl -X PUT "https://openpanel.sh/api/v1/projects/$PROJECT_ID/variables/API_URL" \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "value": "http://${{api.HOST}}:${{api.PORT}}", "serviceId": "'"$WEB_SERVICE_ID"'" }'

How they are worked out

  • At each deploy. Setting a value with a reference checks nothing yet. The deploy works out every reference, and the deployment keeps the result.
  • Nested. A referenced variable may hold references itself, up to five deep.
  • Secrets stay secret. A value that refers to a secret becomes a secret: its worked-out value is sealed and sent to the server the way a secret is, never stored in clear.
  • Lists show what you typed. openpanel env and the API show the reference, not the value it stands for.

When a reference is wrong

The deploy is refused, and the service keeps running what it ran:

MessageWhat to do
"API_URL refers to ${{api.HOST}}, which is not set."Set HOST on the service api or as a shared variable, or fix the name. The service name is the one in the reference, in lowercase.
"API_URL refers to itself, or nests references more than 5 deep."A chain of references loops back, or goes deeper than five.

Services reaching each other

A reference copies a value; it does not make one service reachable from another. Services of a project that run on the same server reach each other by service name on the project's own network, such as http://api:3000. See Services.