fn::eval
The fn::eval built-in function evaluates a template expression in the context of the current environment. Together with fn::template, it enables late binding — the ability to define reusable expressions in one environment and evaluate them with different values in another.
Declaration
fn::eval: template-reference
Parameters
| Property | Type | Description |
|---|---|---|
template-reference | any | A reference to a value defined with fn::template. Typically an interpolation like ${environments.org.defn.my-template}. |
Returns
The result of evaluating the referenced template in the context of the calling environment. The template’s interpolations are resolved using the values available in the environment where fn::eval is called, not where the template is defined.
Example
Reusable greeting template
This example shows how to define a template in one environment and evaluate it in multiple environments with different values.
Template environment (example/defn)
values:
hello:
fn::template: Hello ${name}!
The fn::template expression defines a template that references ${name}. The interpolation is not resolved in this environment — it is deferred until a consumer evaluates it with fn::eval.
Consumer environment A (example/a)
values:
name: "foo"
example:
fn::eval: ${environments.example.defn.hello}
Consumer environment B (example/b)
values:
name: "bar"
example:
fn::eval: ${environments.example.defn.hello}
Parent environment
values:
a: ${environments.example.a}
b: ${environments.example.b}
Evaluated result
{
"a": {
"example": "Hello foo!",
"name": "foo"
},
"b": {
"example": "Hello bar!",
"name": "bar"
}
}
Environment A resolves the template with name: "foo", producing "Hello foo!". Environment B resolves the same template with name: "bar", producing "Hello bar!".
Related functions
fn::template— defines a template expression for deferred evaluation.
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.