Logo

dev-resources.site

for different kinds of informations.

Experimental WASM/Rust support for Pulumi

Published at
8/15/2024
Categories
devops
rust
opensource
pulumi
Author
andrzejressel
Categories
4 categories in total
devops
open
rust
open
opensource
open
pulumi
open
Author
13 person written this
andrzejressel
open
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 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(())
}
Enter fullscreen mode Exit fullscreen mode

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

pulumi Article's
30 articles in total
Favicon
Pulumi WASM/Rust devlog #3
Favicon
Pulumi WASM/Rust devlog #2
Favicon
Pulumi WASM/Rust devlog #1
Favicon
Infrastructure as Code: Comparing Pulumi and HCL Approaches
Favicon
Unlocking the Power of Azure Functions Flex Consumption Plan with Pulumi
Favicon
Pulumi with Terraform – the easy way
Favicon
Experimental WASM/Rust support for Pulumi
Favicon
Pulumi in Python: Translating Interpolation
Favicon
What Is Pulumi And How To Use It
Favicon
Pulumi-Day1- Getting Started
Favicon
Pulumi: Empowering Infrastructure Engineers with Real Programming Languages
Favicon
Pulumi vs Terraform: An In-Depth Comparison
Favicon
Pulumi Has Wowed Me
Favicon
Pulumi vs Terraform
Favicon
Pulumi in Action: Beyond Terraform to Build HA Web Apps on AKS
Favicon
Using MongoDB Atlas with Azure Kubernetes Service - Coded with Pulumi
Favicon
Allowing GCP Compute Resources to Assume AWS IAM Roles with Pulumi
Favicon
Should you use Terraform or Pulumi?
Favicon
Deploying to Azure from Azure DevOps without secrets
Favicon
Accelerating Releases with Pulumi: My Proxy Project Journey
Favicon
Learning Go by examples: part 12 - Deploy Go apps in Go with Pulumi
Favicon
Infrastructure as Code: A Beginner's Guide
Favicon
Deploying a Database Cluster on DigitalOcean using Pulumi
Favicon
Structuring your Infrastructure as Code
Favicon
Image Label Detection using AWS and Pulumi
Favicon
What is the best `as Code` tool in 2023?
Favicon
Create an Azure-Ready GitHub Repository using Pulumi
Favicon
How I get better feedback on my PRs (and how you can, too)
Favicon
Terraform vs. Pulumi : A Look at Both Tools
Favicon
Introducing Azure Native 2.0

Featured ones: