Skip to content
Closed
Changes from all commits
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
42 changes: 42 additions & 0 deletions crates/cli/src/scaffold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ pub fn scaffold_in_memory_iac(
artifacts_path,
),
);
deployment_runbook_src.push_str(&get_interpolated_program_output_template(
&program_metadata.name,
));
} else {
debug!(
"Skipping program {} deployment in in-memory IaC since the .so file was not found",
Expand Down Expand Up @@ -200,6 +203,17 @@ pub fn scaffold_in_memory_iac(
Ok((runbook_id.into(), runbook_sources, manifest))
}

fn get_interpolated_program_output_template(program_name: &str) -> String {
format!(
r#"
output "{program_name}_program_id" {{
description = "The program ID of the deployed {program_name} program"
value = action.deploy_{program_name}.program_id
}}
"#
)
}

pub fn scaffold_iac_layout(
framework: &Framework,
programs: &[ProgramMetadata],
Expand Down Expand Up @@ -300,6 +314,9 @@ pub fn scaffold_iac_layout(
deployment_runbook_src.push_str(
&framework.get_interpolated_program_deployment_template(&program_metadata.name),
);
deployment_runbook_src.push_str(&get_interpolated_program_output_template(
&program_metadata.name,
));
}

let runbook_name = "deployment";
Expand Down Expand Up @@ -514,3 +531,28 @@ pub fn scaffold_iac_layout(

Ok(())
}

#[cfg(test)]
mod program_output_template_tests {
use super::*;

#[test]
fn every_program_gets_its_own_output_block_separated_by_a_blank_line() {
let mut src = String::new();
for name in ["counter", "vault"] {
src.push_str(&get_interpolated_program_output_template(name));
}
let expected = r#"
output "counter_program_id" {
description = "The program ID of the deployed counter program"
value = action.deploy_counter.program_id
}

output "vault_program_id" {
description = "The program ID of the deployed vault program"
value = action.deploy_vault.program_id
}
"#;
assert_eq!(src.trim(), expected.trim());
}
}
Loading