Skip to main content

isoloom_render/
hcl_builder.rs

1//! The HCL builder: a Terraform module is built as `hcl-rs` structures ([`Block`],
2//! [`Attribute`], [`Expression`]) and written once.
3//!
4//! - Values go in as values: a string is an [`Expression::String`], escaped by `hcl-rs` (quotes,
5//!   backslashes, newlines, and Terraform's `${` and `%{` markers). Text that holds Terraform
6//!   expressions is a [`Template`]: its text is escaped the same way and its expressions are
7//!   interpolated, so nothing in a value can end the string or start an interpolation.
8//! - [`Module`] writes the blocks in the layout `terraform fmt` keeps: two-space indents, the
9//!   `=` of consecutive one-line attributes aligned, one blank line between top-level blocks. A
10//!   list, an object or a function call is written on one line when it fits in [`WIDTH`]
11//!   characters, else one item a line (a call keeps its last argument hugged: `f(a, [`).
12//! - Comments go above a top-level block ([`Module::commented`]): `hcl-rs` has none inside.
13
14mod escape;
15mod expr;
16mod template;
17mod write;
18
19pub use expr::{attr, binary, boolean, call, conditional, entry, for_list, index, list, not, null, number, object, reference, string};
20pub use hcl::expr::BinaryOperator;
21pub use hcl::{Attribute, Block, BlockBuilder, Body, Expression, Structure};
22pub use template::{Piece, Template};
23pub use write::{Module, WIDTH};
24
25/// Why a module couldn't be written (`hcl-rs` documents formatting as infallible: kept typed
26/// rather than assumed).
27pub type Error = hcl::Error;