Experimental WASM/Rust support for Pulumi

I was working on this for the last few months and while it’s still not very ergonomic I believe it’s usable enough to write post about it.

What is Pulumi

Pulumi as basically Terraform, but you write code in your favourite programming langua…


This content originally appeared on DEV Community and was authored by ​Andrzej Ressel

I was working on this for the last few months and while it's still not very ergonomic I believe it's usable enough to write post about it.

What is Pulumi

Pulumi as basically Terraform, but you write code in your favourite programming language. Officially it supports Go, Python, Typescript, C# and Java (kinda). There is also community support for Kotlin and Scala

Why WASM

I'm mostly interested in interopability of WASM and WASI's Component Model. Thanks to component model I can generate WASM module with core logic and others can develop bindings for it in their own language. While currently not many languages support binding generation, I believe with growing popularity of WASM this will change.

Current state

The project is still in pretty rough state. The basic basics works - creating resources, mapping elements (even unknown ones) and passing them works, but it's pretty much it. There are some manual steps that must be made before running the code, versioning is very strict and not much of the pulumi features are implemented (for now only creating resources - nothing more).

I'm currently planning on focusing on UX first and on additional Pulumi features later.

Example code

Here is program that will generate two random strings, where the length of the second one is based on the first one - it's mostly to illustrate that the most interesting thing about Pulumi (arbitrary code execution on generated values) works.

use anyhow::Error;
use pulumi_wasm_random::resource::random_string::{random_string, RandomStringArgs};
use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};

#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let length: Output<i32> = Output::new(&4);
    let random_string_1 = random_string(
        "test_1",
        RandomStringArgs {
            keepers: None.into(),
            length,
            lower: None.into(),
            min_lower: None.into(),
            min_numeric: None.into(),
            min_special: None.into(),
            min_upper: None.into(),
            number: None.into(),
            numeric: None.into(),
            override_special: None.into(),
            special: None.into(),
            upper: None.into(),
        },
    );

    let new_length = random_string_1.result.map(|s| s.len() as i32);

    let random_string_2 = random_string(
        "test_2",
        RandomStringArgs {
            keepers: None.into(),
            length: new_length,
            lower: None.into(),
            min_lower: None.into(),
            min_numeric: None.into(),
            min_special: None.into(),
            min_upper: None.into(),
            number: None.into(),
            numeric: None.into(),
            override_special: None.into(),
            special: None.into(),
            upper: None.into(),
        },
    );

    add_export("result", &random_string_1.result);
    add_export("number_1", &random_string_1.length);
    add_export("number_2", &random_string_2.length);
    Ok(())
}

Repositories

Quick start example that uses Pulumi Random provider: https://github.com/andrzejressel/pulumi-wasm-example

The main repository is located here: https://github.com/andrzejressel/pulumi-wasm

Rustdocs for supported providers (cloudflare, docker and random) are available here: https://andrzejressel.github.io/pulumi-wasm/rust-docs/pulumi_wasm_rust/index.html


This content originally appeared on DEV Community and was authored by ​Andrzej Ressel


Print Share Comment Cite Upload Translate Updates
APA

​Andrzej Ressel | Sciencx (2024-08-15T21:55:25+00:00) Experimental WASM/Rust support for Pulumi. Retrieved from https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/

MLA
" » Experimental WASM/Rust support for Pulumi." ​Andrzej Ressel | Sciencx - Thursday August 15, 2024, https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/
HARVARD
​Andrzej Ressel | Sciencx Thursday August 15, 2024 » Experimental WASM/Rust support for Pulumi., viewed ,<https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/>
VANCOUVER
​Andrzej Ressel | Sciencx - » Experimental WASM/Rust support for Pulumi. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/
CHICAGO
" » Experimental WASM/Rust support for Pulumi." ​Andrzej Ressel | Sciencx - Accessed . https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/
IEEE
" » Experimental WASM/Rust support for Pulumi." ​Andrzej Ressel | Sciencx [Online]. Available: https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/. [Accessed: ]
rf:citation
» Experimental WASM/Rust support for Pulumi | ​Andrzej Ressel | Sciencx | https://www.scien.cx/2024/08/15/experimental-wasm-rust-support-for-pulumi/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.