DEV Community

​Andrzej Ressel
​Andrzej Ressel

Posted on

Pulumi WASM/Rust devlog #1

Since my last post more than half a year have passed. The project is still going strong and a lot of improvements have been introduced.

Builders

Last time, all fields were required (even is they are empty):

    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(),
        },
    );
Enter fullscreen mode Exit fullscreen mode

I've migrated all the structs to bon so now they look like this

    let random_string_1 = random_string::create(
        "test_1",
        RandomStringArgs::builder().length(length).build_struct(),
    );
Enter fullscreen mode Exit fullscreen mode

In the future I will experiment with Function Builder to see if it will be a better choice

Code generation

Last time provider was split into two parts - WASM based provider (generated on Pulumi WASM side and distributed as binary artifact) and glue code (potentially generated on user side, last time still generated by Pulumi WASM).

I've decided to go 100% for code generation on user side. Thanks to that user can use any provider they want in any version they want. In addition provider does not have to be available in public Pulumi registry - glue code can be generated from schema.json.

# build.rs
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
    pulumi_wasm_build::generate("random", "4.15.0")?;
    Ok(())
}
Enter fullscreen mode Exit fullscreen mode

Examples

Currently Pulumi does not export code examples in easy to ingest format. I've decided to try reading YAML and the results are pretty good - for now it's very basic and things like variables, interpolation and complicated order does not work. Here is example of ACMPCA Permission

use pulumi_wasm_rust::Output;
use pulumi_wasm_rust::{add_export, pulumi_main};
#[pulumi_main]
fn test_main() -> Result<(), Error> {
    let example = permission::create(
        "example",
        PermissionArgs::builder()
            .actions(vec!["IssueCertificate", "GetCertificate", "ListPermissions",])
            .certificate_authority_arn("${exampleCertificateAuthority. arn}")
            .principal("acm.amazonaws.com")
            .build_struct(),
    );
    let exampleCertificateAuthority = certificate_authority::create(
        "exampleCertificateAuthority",
        CertificateAuthorityArgs::builder()
            .certificate_authority_configuration(
                CertificateAuthorityCertificateAuthorityConfiguration::builder()
                    .keyAlgorithm("RSA_4096")
                    .signingAlgorithm("SHA512WITHRSA")
                    .subject(
                        CertificateAuthorityCertificateAuthorityConfigurationSubject::builder()
                            .commonName("example. com")
                            .build_struct(),
                    )
                    .build_struct(),
            )
            .build_struct(),
    );
}
Enter fullscreen mode Exit fullscreen mode

There are still a lot of things to do - generating the biggest providers (AWS almost works), core improvements (there are non-working edge cases,
like functions without inputs), example generation improvements, documentation and creating PoC of non-rust WASM language.

Links:
Main repository: https://github.com/andrzejressel/pulumi-wasm
Example: https://github.com/andrzejressel/pulumi-wasm-example

Top comments (0)