-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopentofu_templates.rs
More file actions
66 lines (57 loc) · 2.05 KB
/
Copy pathopentofu_templates.rs
File metadata and controls
66 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! `OpenTofu` template rendering step
//!
//! This module provides the `RenderOpenTofuTemplatesStep` which handles rendering
//! of `OpenTofu` configuration templates to the build directory. This step prepares
//! infrastructure configuration files for `OpenTofu` operations.
//!
//! ## Key Features
//!
//! - Static template rendering for `OpenTofu` configurations
//! - Integration with the `TofuTemplateRenderer` for file generation
//! - Build directory preparation for infrastructure operations
//! - Comprehensive error handling for template processing
//!
//! ## Usage Context
//!
//! This step is typically executed early in the deployment workflow, before
//! infrastructure provisioning, to prepare the `OpenTofu` configuration files
//! needed for infrastructure operations.
use std::sync::Arc;
use tracing::{info, instrument};
use crate::infrastructure::templating::tofu::{TofuProjectGenerator, TofuProjectGeneratorError};
/// Simple step that renders `OpenTofu` templates to the build directory
pub struct RenderOpenTofuTemplatesStep {
tofu_template_renderer: Arc<TofuProjectGenerator>,
}
impl RenderOpenTofuTemplatesStep {
#[must_use]
pub fn new(tofu_template_renderer: Arc<TofuProjectGenerator>) -> Self {
Self {
tofu_template_renderer,
}
}
/// Execute the template rendering step
///
/// # Errors
///
/// Returns an error if the template rendering fails or if there are issues
/// with the template manager or renderer.
#[instrument(
name = "render_opentofu_templates",
skip_all,
fields(step_type = "rendering", template_type = "opentofu")
)]
pub async fn execute(&self) -> Result<(), TofuProjectGeneratorError> {
info!(
step = "render_opentofu_templates",
"Rendering OpenTofu templates"
);
self.tofu_template_renderer.render().await?;
info!(
step = "render_opentofu_templates",
status = "success",
"OpenTofu templates rendered successfully"
);
Ok(())
}
}