Skip to content

spin up should check required variables #3115

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

Open
ThorstenHans opened this issue Apr 16, 2025 · 1 comment
Open

spin up should check required variables #3115

ThorstenHans opened this issue Apr 16, 2025 · 1 comment

Comments

@ThorstenHans
Copy link
Contributor

Currently, the spin up command does not check if required variables are provided when launching the application.

Consider a Spin application with the following manifest:

spin_manifest_version = 2

[application]
name = "test"
version = "0.1.0"
description = ""

[variables]
foo = { required = true }

[[trigger.http]]
route = "/..."
component = "test"

[component.test]
source = "target/wasm32-wasip1/release/test.wasm"
allowed_outbound_hosts = []

[component.test.variables]
foo = "{{foo}}"

[component.test.build]
command = "cargo build --target wasm32-wasip1 --release"
watch = ["src/**/*.rs", "Cargo.toml"]
use spin_sdk::http::{IntoResponse, Request, Response};
use spin_sdk::{http_component, variables};
#[http_component]
fn handle_test_var(_: Request) -> anyhow::Result<impl IntoResponse> {
    match variables::get("foo") {
        Ok(value) => println!("{}", value),
        Err(r) => println!("{}", r),
    };
    Ok(Response::new(200, ()))
}

Expected behavior

I expect spin up to bail out and prevent from launching the app - if the required variable foo is not specified (e.g., by setting the SPIN_VARIABLE_FOO environment variable)

Actual behavior

I can start the app locally using spin up. Sending a request to the app (which tries to load the foo variable will result in a runtime error:

Error::Provider("no provider resolved required variable \"foo\"")

Spin Version

I see this behavior with current spin version (tested 3.0.0, 3.1.2 and 3.2.0)

@itowlson
Copy link
Collaborator

Variables are lazily loaded each time they are accessed. I guess we could evaluate if the runtime config contains only the environment provider, where the set of variables and values can't change after startup, and do validation in that case.

Alternatively I think @lann has suggested switching variables to be read once at startup in which case this would happen automatically. (Sorry Lann if I am misremembering.) That's a breaking change though.

@michelleN michelleN moved this to Triage Needed in Spin Triage May 5, 2025
@fibonacci1729 fibonacci1729 moved this from Triage Needed to Investigating / Open For Comment in Spin Triage May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Investigating / Open For Comment
Development

No branches or pull requests

2 participants