Skip to content

spin up should check required variables #3115

@ThorstenHans

Description

@ThorstenHans

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Investigating / Open For Comment

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions