polite-mechanic-60124
12/07/2021, 9:15 PMuser_data=pulumi.Output.all(
{
"cluster_size": cluster_size,
"secret_id": secret_id,
}
).apply(
lambda args: render_user_data_output(
templating_env(),
"userdata-server.sh.jinja",
*args,
)
),
Now for the weird part. If render_user_data_output returns a string, I get a base64 encoded pulumi object address in memory. If it returns a pulumi Output, then it renders the base64 encoded secret. Both versions defined below
def render_user_data_output(
env: Environment, template_name: str, kwargs: Mapping[str, Any]
) -> str:
rendered_template = render_template_file(env, template_name, kwargs)
return base64.b64encode(rendered_template.encode("utf-8")).decode("utf-8")
def render_user_data_output(
env: Environment, template_name: str, kwargs: Mapping[str, Any]
) -> pulumi.Output:
rendered_template = render_template_file(env, template_name, kwargs)
return pulumi.Output.from_input(base64.b64encode(rendered_template.encode("utf-8")).decode("utf-8"))
Does anyone know what's going on here?prehistoric-activity-61023
12/07/2021, 9:21 PMpulumi.Output
works as expected?polite-mechanic-60124
12/07/2021, 9:21 PMprehistoric-activity-61023
12/07/2021, 9:24 PMrender_template_file
defined by you?polite-mechanic-60124
12/07/2021, 9:38 PMfrom jinja2 import Environment, PackageLoader, StrictUndefined, select_autoescape
def templating_env() -> Environment:
"""Returns a Jinja templating environment that pulls templates from the `infra.templates` package.
If any expected variables are missing from a template rendering,
an error will be thrown.
"""
return Environment(
loader=PackageLoader("infra"),
autoescape=select_autoescape(),
undefined=StrictUndefined,
)
def render_template_file(
env: Environment, template_name: str, kwargs: Mapping[str, Any]
) -> str:
"""
Render the given Jinja template with the given arguments.
"""
template = env.get_template(template_name)
return template.render(**kwargs)