Dynamic Values
Last updated
Last updated
Copyright© 2023 CloudTruth
The dynamic values option provides the ability to reference parameters (standard or secret), templates, or other CloudTruth objects (project, environment, template) within a company's organization and interpolate their values. Dynamic values are obtained by using the mustache logic-less template syntax.
Only non-secret parameters can contain Dynamic Values; however, they can reference parameters marked as secrets.
After creating a new standard parameter, the ADD ENVIRONMENT VALUE
modal is displayed, where clicking the DYNAMIC
option switches the ENVIRONMENT VALUE
input into a code editor and adds the Evaluate
button for previewing the dynamic value before saving:
Starting with two left-hand braces {{
, the editor will automatically insert the two right-hand braces }}
. Start typing cloudtruth
to access the available automatic parameter options, we'll select project
for this example:
Click Evaluate
to display the actual value of the parameter (to revert back the the code editor, click Show Raw
):
Once satisfied, click Save
to save the dynamic value.
More information regarding available automatic parameters is covered in our Templates documentation in the Automatic Parameters section
The ability to interpolate, or retrieve values from existing parameters, is a great way to automatically produce values for a given environment based on data within the environment. Here's a simple example:
Say we want to programmatically build a site per environment within a project. Normally, we would need to add a domain parameter for each environment which is unique such as:
production.example-app.com
Hard-coding these parameters and overriding the values in each environment is doable, but quickly becomes overhead and error prone when new environments are created. Interpolation gives us the ability to 'build' this value at retrieval time, every time. When new environments are added, the dynamic variable is inherited and produces the correct value when retrieved without the need to manually update the value. Here's how we might do this:
Create a new project parameter for the default environment with a dynamic value which references the project:
This will produce a domain with top-level-domain base for the project:
Next, let's create another project parameter for the default environment with a dynamic value which references the environment and the previously created project parameter:
This will produce the full-domain string in a per environment fashion for the project:
Going back to the project's parameter list, we can see how useful this is by evaluating the values (click Show Evaluated
) then selecting different environments to see the value update to reflect the currently selected environment:
This is a simple example of how interpolation produces values automatically and accurately every time they are retrieved and evaluated.