Skip to content

Wasm

Please Read First

Before proceeding, make sure to read this Overview page to get a better understanding of the documentation.

In Pulumi Gestalt, Wasm support is based on the Component Model.

Artifacts

Several artifacts related to Wasm support can be found on the releases page:

  • Wasm implementation (pulumi_gestalt-debug.wasm / pulumi_gestalt-release.wasm)
  • Runner (pulumi_gestalt_wasm_runner)
  • WIT files (world.wit, pulumi-gestalt-external.wit)

The key artifacts are the Runner and WIT files. The Runner automatically downloads the corresponding Wasm implementation from the releases page when the program is executed.

Versioning

Currently, WIT files follow nightly versioning. Integrations should select a nightly version of Pulumi Gestalt to ensure compatibility. The Runner downloads the corresponding Wasm implementation and merges them into a single Wasm file.

Entrypoint

The entry point is managed by the component:pulumi-gestalt-external/pulumi-main interface. This function is invoked by pulumi-gestalt-runner. It takes a single argument, in-preview, which should be passed to the context constructor.

Callback Emulation

TODO

Runner Quick Start

To execute a Pulumi Gestalt Wasm program using the Runner, use:

pulumi_wasm_runner run <WASM_FILE>

This downloads the corresponding Wasm implementation, merges it with the specified Wasm file, and runs the program. To use the debug version of Wasm, add the --debug flag.

WIT Files

world.wit
package component:pulumi-gestalt@0.0.0-test2;

world pulumi-gestalt {
    export output-interface;
    export register-interface;
    export stack-interface;
    export pulumi-engine;

    import component:pulumi-gestalt-external/log@0.0.0-STABLE-DEV;
    import component:pulumi-gestalt-external/external-world@0.0.0-STABLE-DEV;
}

world client {
    import output-interface;
    import stack-interface;
    import register-interface;
    import pulumi-engine;
    export component:pulumi-gestalt-external/pulumi-main@0.0.0-STABLE-DEV; // Used by macro
}

world logger {
    import component:pulumi-gestalt-external/log@0.0.0-STABLE-DEV;
}

world runner {
    export component:pulumi-gestalt-external/pulumi-main@0.0.0-STABLE-DEV;
    import component:pulumi-gestalt-external/external-world@0.0.0-STABLE-DEV;
    import component:pulumi-gestalt-external/log@0.0.0-STABLE-DEV;
}

interface pulumi-engine {
    resource engine {
        constructor(in-preview: bool);
    }
}

interface output-interface {
    use pulumi-engine.{engine};

    resource output {
        constructor(engine: borrow<engine>, value: string, secret: bool);
        map: func(function-name: string) -> output;
        clone: func() -> output;
    }
    combine: func(outputs: list<borrow<output>>) -> output;

    resource register-output {
        extract-field: func(field-name: string) -> output;
    }
}

interface stack-interface {
    use pulumi-engine.{engine};
    use output-interface.{output};

    record function-invocation-request {
        id: output,
        function-id: string,
        value: string,
    }
    record function-invocation-result {
        id: borrow<output>,
        value: string,
    }
    add-export: func(name: string, value: borrow<output>);
    finish: func(engine: borrow<engine>, functions: list<function-invocation-result>) -> list<function-invocation-request>;
}

interface register-interface {
    use pulumi-engine.{engine};
    use output-interface.{output, register-output};

    record object-field {
        name: string,
        value: borrow<output>
    }

    record register-resource-request {
        %type: string,
        name: string,
        version: string,
        object: list<object-field>,
    }

    register: func(engine: borrow<engine>, request: register-resource-request) -> register-output;

    record resource-invoke-request {
        token: string,
        version: string,
        object: list<object-field>,
    }

    invoke: func(engine: borrow<engine>, request: resource-invoke-request) -> register-output;
}
pulumi-gestalt-external.wit
package component:pulumi-gestalt-external@0.0.0-STABLE-DEV;

interface external-world {
    register-resource-outputs: func(request: list<u8>);

    record resource-invoke-request {
        output-id: string,
        body: list<u8>
    }

    record register-resource-request {
        output-id: string,
        body: list<u8>
    }

    record registered-resource {
        output-id: string,
        body: list<u8>
    }

    resource-invoke: func(request: resource-invoke-request);
    register-resource: func(request: register-resource-request);
    wait-for-resource-operations: func() -> list<registered-resource>;
}

interface log {
    enum level {
        TRACE,
        DEBUG,
        INFO,
        WARN,
        ERROR
    }

    record content {
        level: level,
        target: string,
        args: string,
        module-path: option<string>,
        file: option<string>,
        line: option<u32>,
        key-values: list<tuple<string, string>>
    }

    log: func(content: content);
}

interface pulumi-main {
    main: func(in-preview: bool);
}

The relevant integration world for Pulumi Gestalt is client.