Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create a template with a component and variables #2205

Closed
kate-goldenring opened this issue Dec 29, 2023 · 1 comment · Fixed by fermyon/developer#1115
Closed

Cannot create a template with a component and variables #2205

kate-goldenring opened this issue Dec 29, 2023 · 1 comment · Fixed by fermyon/developer#1115
Assignees

Comments

@kate-goldenring
Copy link
Contributor

kate-goldenring commented Dec 29, 2023

Problem

I cannot create a template that contains a component that requires variables. Specifically, I am trying to update the KV explorer to use the config store for user/pass credentials, which requires adding variables to the template: fermyon/spin-kv-explorer#27.

This shows up in the Spin tests if you update update the add-variables test template as done here to include a component that requires the variables added via variables.txt. If you then run the manager::tests::can_add_variables_from_template test, it errors with

thread 'manager::tests::can_add_variables_from_template' panicked at 'called `Result::unwrap()` on an `Err` value: liquid: Unknown variable
  with:
    requested variable=secret
', crates/templates/src/manager.rs:1017:50

It seems we may need to expand upon variables support in templates (added here #1864) to consider the case when a component is being added.

Solution

I tried updating the renderer and writer to process "variables" first but was not successful.

@kate-goldenring kate-goldenring changed the title Cannot add a component with variables Cannot create a template with a component and variables Dec 29, 2023
@itowlson itowlson self-assigned this Jan 2, 2024
@itowlson
Copy link
Contributor

itowlson commented Jan 2, 2024

In your sample, this happens because in the line

kv_credentials = "{{ secret }}"

the template system sees {{ secret }} as a reference to a template variable. Double braces need to be escaped. From initial tests,

{% raw %}kv_credentials = "{{ secret }}"{% endraw %}

at least doesn't error; I will update the unit test to verify it produces the right result. I should also update the docs to tell people how to do this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants