Expand description
§tfparser-core
Parse a Terraform / Terragrunt source repository into a typed in-memory IR
that can be exported as Parquet — without running terraform plan.
§Quick start
One-shot parse with all defaults:
let workspace = tfparser_core::parse("./my-tf-repo")?;
println!(
"{} components / {} modules / {} resources",
workspace.components.len(),
workspace.modules.len(),
workspace.components.iter().map(|c| c.resources.len()).sum::<usize>(),
);Builder for full control + Parquet export in one call:
use std::sync::Arc;
use std::path::Path;
use tfparser_core::{Parser, EnvVarMode, ExportOptions};
let parser = Parser::builder()
.workspace_root("./my-tf-repo")
.environment("production")
.default_region("us-west-2")?
.env_var_mode(EnvVarMode::Passthrough)
.allow_env("TF_VAR_environment")
.var("region", "us-east-1")
.strict_providers(true)
.build()?;
let export_opts = ExportOptions::builder()
.out_dir(Arc::<Path>::from(Path::new("./out")))
.overwrite(true)
.build();
let (workspace, report) = parser.parse_and_export(&export_opts)?;
eprintln!("wrote {} rows in {} ms", report.total_rows, report.elapsed.as_millis());Bring everything in scope with the prelude:
use tfparser_core::prelude::*;§Surface map
| I want to … | Reach for |
|---|---|
| parse a repo with defaults | parse |
| parse + tune env / vars / limits | Parser::builder |
| parse and write Parquet in one call | Parser::parse_and_export |
| inspect the parsed IR | ir::Workspace, ir::Component, ir::Resource |
| swap in a stub for tests | implement Pipeline / Exporter |
| configure parquet output (compression, manifest, tables) | ExportOptions::builder + ParquetExporter |
| load an AWS profile map | load_aws_config / load_yaml_profile_map |
§Engineering invariants
#![forbid(unsafe_code)]at the crate root — nounsafe, ever.- No
unwrap/expect/panicreachable from external input; the workspace lints deny those clippy categories for every member. - Every public type is
#[non_exhaustive]so future fields are additive. - Public
Debugimpls redact sensitive fields (provider secrets, resolved values that may carry credentials).
See ./specs/91-impl-plan.md for the build-order rationale and
./specs/10-data-model.md for the IR contract pinned in this crate.
Re-exports§
pub use diagnostic::Diagnostic;pub use diagnostic::LimitKind;pub use diagnostic::Severity;pub use error::Error;pub use error::Result;pub use error::ValidationError;pub use eval::EnvVarMode;pub use eval::EvalContext;pub use eval::EvalError;pub use eval::EvalLimits;pub use eval::EvaluatedComponent;pub use eval::Evaluator;pub use eval::FuncRegistry;pub use eval::HclEvaluator;pub use exporter::CompressionOpt;pub use exporter::ExportOptions;pub use exporter::ExportReport;pub use exporter::ExportedFile;pub use exporter::Exporter;pub use exporter::ParquetExporter;pub use exporter::SecondaryTable;pub use graph::DefaultGraphBuilder;pub use graph::ExternalModuleRef;pub use graph::GraphBuilder;pub use graph::GraphContext;pub use graph::GraphError;pub use graph::ModuleRegistry;pub use ir::AccountId;pub use ir::Address;pub use ir::AssumeRole;pub use ir::AttributeMap;pub use ir::BinaryOp;pub use ir::BlockKind;pub use ir::Component;pub use ir::ComponentId;pub use ir::ComponentKind;pub use ir::DependencyBlock;pub use ir::Edge;pub use ir::EdgeKind;pub use ir::Environment;pub use ir::Expression;pub use ir::FileExt;pub use ir::GenerateBlock;pub use ir::IncludePath;pub use ir::Local;pub use ir::Map;pub use ir::Module;pub use ir::ModuleCall;pub use ir::ModuleId;pub use ir::ModuleSource;pub use ir::Output;pub use ir::ProviderBlock;pub use ir::ProviderRef;pub use ir::Region;pub use ir::Resource;pub use ir::ResourceKind;pub use ir::SourceFile;pub use ir::Span;pub use ir::StateBackend;pub use ir::SymbolKind;pub use ir::Symbolic;pub use ir::TerragruntConfig;pub use ir::UnaryOp;pub use ir::Value;pub use ir::Variable;pub use ir::Workspace;pub use parser::Parser;pub use parser::ParserBuilder;pub use parser::parse;pub use pipeline::DefaultPipeline;pub use pipeline::Pipeline;pub use pipeline::PipelineOptions;pub use provider::DefaultProviderResolver;pub use provider::ProfileEntry;pub use provider::ProfileMap;pub use provider::ProviderContext;pub use provider::ProviderError;pub use provider::ProviderResolver;pub use provider::empty_profile_map;pub use provider::extract_account_id;pub use provider::load_aws_config;pub use provider::load_yaml_profile_map;pub use terragrunt::FsTerragruntResolver;pub use terragrunt::TerragruntError;pub use terragrunt::TerragruntResolver;pub use terragrunt::TgContext;
Modules§
- diagnostic
- Non-fatal diagnostics attached to the workspace IR.
- discovery
- Workspace discovery — the first cross-trust-boundary phase.
- error
- Top-level error type for
tfparser-core. - eval
- Best-effort HCL expression evaluator.
- exporter
- Parquet exporter — turns a
Workspaceintoresources.parquet(+workspace.manifest.json) on disk per 20-parquet-exporter.md. - graph
- Resource graph: flatten module bodies into their callers, expand
count/for_each, and emit aWorkspace. - ir
- In-memory intermediate representation.
- loader
- HCL loader: read source files for a discovered component, parse them
with
hcl-edit, lower to our IR, and produce aRawComponent. - parser
- High-level
Parserfacade — the recommended consumption surface. - pipeline
- Top-level pipeline trait + default implementation.
- prelude
- Common types bundled for
use tfparser_core::prelude::*;. - projection
RawComponent→ IR projection.- provider
- Provider / account / region resolver (Phase 7, closes M4).
- terragrunt
- Terragrunt-mimicking resolver.