Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better optional values handling #430

Merged
merged 10 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ crate-type = ["cdylib"]
anyhow.workspace = true
pulumi_wasm_rust.workspace = true
pulumi_wasm_random.workspace = true
log = "0.4.22"

[dev-dependencies]
assert_cmd.workspace = true
Expand Down
6 changes: 4 additions & 2 deletions examples/simple/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ local-test:
cargo component build -p pulumi_wasm_example_simple --release
cargo component build -p pulumi_wasm_random_provider --release
$env:PULUMI_CONFIG_PASSPHRASE=" "
pulumi destroy -y
pulumi up -y
pulumi preview
# pulumi up -y
# pulumi destroy -y
# pulumi up -y
12 changes: 12 additions & 0 deletions examples/simple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Error;
use log::info;
Fixed Show fixed Hide fixed
use pulumi_wasm_random::random_string;
use pulumi_wasm_random::random_string::RandomStringArgs;
use pulumi_wasm_rust::Output;
Expand All @@ -13,12 +14,16 @@ fn test_main() -> Result<(), Error> {
RandomStringArgs::builder().length(length).build_struct(),
);


// Tests preview behaviour for unknown fields
let t = random_string.result.map(|s| format!("Result: {s}"));

// Tests number mapping
let number = random_string.min_upper.map(|i| i * 2);

// Optional values are deserialized as None
let keepers = random_string.keepers.map(|map| format!("Keepers: {map:?}"));

let val1 = Output::new(&1);
let val2 = Output::new(&"abc".to_string());

Expand All @@ -29,10 +34,17 @@ fn test_main() -> Result<(), Error> {
let combined_string = combined.map(|values| format!("Values: {values:?}"));
let combined_2_string = combined_2.map(|values| format!("Values: {values:?}"));

let random_string_2 = random_string::create(
"test_2",
RandomStringArgs::builder().length(keepers.map(|s| {info!("TEST: {}", s); s.len() as i32})).build_struct(),
);

add_export("result", &random_string.result);
add_export("transformed_result", &t);
add_export("number", &number);
add_export("combined_string", &combined_string);
add_export("combined_2_string", &combined_2_string);
add_export("keepers", &keepers);
add_export("result_2", &random_string_2.result);
Ok(())
}
Loading
Loading