Skip to content

Commit

Permalink
Implement stack exports (#55)
Browse files Browse the repository at this point in the history
Fixes #54
  • Loading branch information
andrzejressel authored Mar 18, 2024
1 parent baf36f0 commit c1861e0
Show file tree
Hide file tree
Showing 18 changed files with 577 additions and 293 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,7 @@ jobs:

- name: Run tests
run: cargo test --all --verbose
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Ensure no files have changed
run: git diff --exit-code
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ version = "0.1.0"
edition = "2021"

[workspace.dependencies]
pulumi_wasm_rust = { path = "pulumi_wasm_rust" }
pulumi_wasm_rust_macro = { path = "pulumi_wasm_rust_macro" }
wasm_common = { path = "wasm_common" }
pulumi_wasm_provider_random_rust = { path = "providers/pulumi_wasm_provider_random_rust" }

anyhow = "1.0.81"
prost = "0.12.3"
prost-types = "0.12.3"
Expand Down Expand Up @@ -52,10 +57,6 @@ regex = "1.10.3"
syn = { version = "2.0.53", features = ["full"] }
quote = "1.0.35"
proc-macro2 = "1.0.79"
pulumi_wasm_rust = { path = "pulumi_wasm_rust" }
pulumi_wasm_rust_macro = { path = "pulumi_wasm_rust_macro" }
wasm_common = { path = "wasm_common" }
pulumi_wasm_provider_random_rust = { path = "providers/pulumi_wasm_provider_random_rust" }
assert_cmd = "2.0.14"
predicates = "3.1.0"
normpath = "1.2"
Expand Down
5 changes: 3 additions & 2 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Error;
use pulumi_wasm_provider_random_rust::random::{create_random_string, RandomStringArgs};
use pulumi_wasm_rust::output::Output;
use pulumi_wasm_rust::pulumi_main;
use pulumi_wasm_rust::{add_export, pulumi_main};

// Causes compilation errors
// Generated by cargo-component
Expand All @@ -10,9 +10,10 @@ use pulumi_wasm_rust::pulumi_main;
#[pulumi_main]
fn test_main() -> Result<(), Error> {
let length: Output<i32> = Output::new(&12).map(|i: i32| i * 3);
let _ = create_random_string(RandomStringArgs {
let random_string = create_random_string(RandomStringArgs {
name: "test",
length,
});
add_export("result", random_string.result);
Ok(())
}
16 changes: 12 additions & 4 deletions examples/simple/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ use std::process::Command;
use assert_cmd::prelude::*;
use std::str;
use anyhow::anyhow;
use serde_json::{json, Value};
use serde_json::Value;

#[test]
fn test_integration() -> Result<(), anyhow::Error> {

let github_token_env_vars = if let Ok(token) = std::env::var("GITHUB_TOKEN") {
vec![("GITHUB_TOKEN".to_string(), token)]
} else {
vec![]
};

Command::new("pulumi")
.args(["stack", "init", "test"])
.env("PULUMI_CONFIG_PASSPHRASE", " ")
.envs(github_token_env_vars.clone())
.current_dir(".")
.output()?;

Expand All @@ -23,11 +30,12 @@ fn test_integration() -> Result<(), anyhow::Error> {
.args(["up", "-y"])
.current_dir(".")
.env("PULUMI_CONFIG_PASSPHRASE", " ")
.envs(github_token_env_vars)
.assert()
.success();

let binding = Command::new("pulumi")
.args(["stack", "export"])
.args(["stack", "output", "--json"])
.current_dir(".")
.env("PULUMI_CONFIG_PASSPHRASE", " ")
.assert()
Expand All @@ -38,9 +46,9 @@ fn test_integration() -> Result<(), anyhow::Error> {

let stack: Value = serde_json::from_str(str::from_utf8(stack)?)?;

let length = stack.pointer("/deployment/resources/1/inputs/length").ok_or(anyhow!("Cannot find length in stack export"))?;
let result = stack.pointer("/result").ok_or(anyhow!("Cannot find [result] in stack export"))?.as_str().ok_or(anyhow!("[result] is not a string"))?;

assert_eq!(length, &json!(36));
assert_eq!(result.len(), 36);

Ok(())
}
55 changes: 16 additions & 39 deletions providers/pulumi_wasm_provider_random/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,6 @@ pub mod component {
_rt::bool_lift(ret as u8)
}
}
#[allow(unused_unsafe, clippy::all)]
pub fn combine_outputs() -> bool {
unsafe {
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "component:pulumi-wasm/[email protected]")]
extern "C" {
#[link_name = "combine-outputs"]
fn wit_import() -> i32;
}

#[cfg(not(target_arch = "wasm32"))]
fn wit_import() -> i32 {
unreachable!()
}
let ret = wit_import();
_rt::bool_lift(ret as u8)
}
}
impl Output {
#[allow(unused_unsafe, clippy::all)]
pub fn new(value: &[u8]) -> Self {
Expand Down Expand Up @@ -407,10 +389,6 @@ pub mod exports {
use super::super::super::super::_rt;
pub type Output =
super::super::super::super::component::pulumi_wasm::output_interface::Output;
/// variant either-u32 {
/// literal(option<u32>),
/// res(option<borrow<output>>),
/// }
pub struct RandomStringArgs<'a> {
pub name: _rt::String,
pub length: &'a Output,
Expand Down Expand Up @@ -644,29 +622,28 @@ pub(crate) use __export_pulumi_provider_random_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.20.0:pulumi-provider-random:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1030] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xf9\x06\x01A\x02\x01\
A\x07\x01B\x16\x04\0\x06output\x03\x01\x01p}\x01i\0\x01@\x01\x05value\x01\0\x02\x04\
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1010] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe5\x06\x01A\x02\x01\
A\x07\x01B\x15\x04\0\x06output\x03\x01\x01p}\x01i\0\x01@\x01\x05value\x01\0\x02\x04\
\0\x13[constructor]output\x01\x03\x01h\0\x01@\x02\x04self\x04\x0dfunction-names\0\
\x02\x04\0\x12[method]output.map\x01\x05\x01k\x01\x01@\x01\x04self\x04\0\x06\x04\
\0\x12[method]output.get\x01\x07\x01@\x02\x04self\x04\x05fields\0\x02\x04\0\x18[\
method]output.get-field\x01\x08\x01@\x01\x04self\x04\0s\x04\0\x17[method]output.\
get-type\x01\x09\x01@\x01\x04self\x04\0\x02\x04\0\x18[method]output.duplicate\x01\
\x0a\x01@\0\0s\x04\0\x10describe-outputs\x01\x0b\x01@\0\0\x7f\x04\0\x0fnon-done-\
exists\x01\x0c\x04\0\x0fcombine-outputs\x01\x0c\x03\x01,component:pulumi-wasm/ou\
[email protected]\x05\0\x02\x03\0\0\x06output\x01B\x0b\x02\x03\x02\x01\x01\x04\
\0\x06output\x03\0\0\x01h\x01\x01r\x02\x04names\x05value\x02\x04\0\x0cobject-fie\
ld\x03\0\x03\x01p\x04\x01r\x03\x04types\x04names\x06object\x05\x04\0\x19register\
-resource-request\x03\0\x06\x01i\x01\x01@\x01\x07request\x07\0\x08\x04\0\x08regi\
ster\x01\x09\x03\x01.component:pulumi-wasm/[email protected]\x05\x02\x01B\
\x0c\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01r\x02\x04names\x06l\
ength\x02\x04\0\x12random-string-args\x03\0\x03\x01i\x01\x01r\x01\x06result\x05\x04\
\0\x14random-string-result\x03\0\x06\x01@\x01\x04args\x04\0\x07\x04\0\x14create-\
random-string\x01\x08\x01@\0\x01\0\x04\0\x10handle-functions\x01\x09\x04\x01<com\
ponent:pulumi-wasm/[email protected]\x05\x03\x04\x012compon\
ent:pulumi-wasm/[email protected]\x04\0\x0b\x1c\x01\0\x16pulumi-provi\
der-random\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070\
.201.0\x10wit-bindgen-rust\x060.20.0";
exists\x01\x0c\x03\x01,component:pulumi-wasm/[email protected]\x05\0\x02\x03\
\0\0\x06output\x01B\x0b\x02\x03\x02\x01\x01\x04\0\x06output\x03\0\0\x01h\x01\x01\
r\x02\x04names\x05value\x02\x04\0\x0cobject-field\x03\0\x03\x01p\x04\x01r\x03\x04\
types\x04names\x06object\x05\x04\0\x19register-resource-request\x03\0\x06\x01i\x01\
\x01@\x01\x07request\x07\0\x08\x04\0\x08register\x01\x09\x03\x01.component:pulum\
i-wasm/[email protected]\x05\x02\x01B\x0c\x02\x03\x02\x01\x01\x04\0\x06ou\
tput\x03\0\0\x01h\x01\x01r\x02\x04names\x06length\x02\x04\0\x12random-string-arg\
s\x03\0\x03\x01i\x01\x01r\x01\x06result\x05\x04\0\x14random-string-result\x03\0\x06\
\x01@\x01\x04args\x04\0\x07\x04\0\x14create-random-string\x01\x08\x01@\0\x01\0\x04\
\0\x10handle-functions\x01\x09\x04\x01<component:pulumi-wasm/pulumi-provider-ran\
[email protected]\x05\x03\x04\x012component:pulumi-wasm/pulumi-provider-random\
@0.1.0\x04\0\x0b\x1c\x01\0\x16pulumi-provider-random\x03\0\0\0G\x09producers\x01\
\x0cprocessed-by\x02\x0dwit-component\x070.201.0\x10wit-bindgen-rust\x060.20.0";

#[inline(never)]
#[doc(hidden)]
Expand Down
10 changes: 8 additions & 2 deletions providers/pulumi_wasm_provider_random_rust/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ pub struct RandomStringArgs<'a> {
pub length: Output<i32>,
}

pub struct RandomString {
pub result: Output<String>,
}

pub fn create_random_string(
args: RandomStringArgs,
) -> Output<String> {
) -> RandomString {
let length = clone(args.length);
let args = pulumi_provider_random_interface::RandomStringArgs {
name: args.name.into(),
length: &length,
};
let result = pulumi_provider_random_interface::create_random_string(&args);

random_to_domain_mapper::<String>(result.result)
RandomString {
result: random_to_domain_mapper(result.result),
}
}

fn random_to_domain_mapper<F: serde::Serialize>(random: pulumi_provider_random_interface::Output) -> Output<F> {
Expand Down
Loading

0 comments on commit c1861e0

Please sign in to comment.