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
Top comments (0)