Skip to main content

Crate tfparser_core

Crate tfparser_core 

Source
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 defaultsparse
parse + tune env / vars / limitsParser::builder
parse and write Parquet in one callParser::parse_and_export
inspect the parsed IRir::Workspace, ir::Component, ir::Resource
swap in a stub for testsimplement Pipeline / Exporter
configure parquet output (compression, manifest, tables)ExportOptions::builder + ParquetExporter
load an AWS profile mapload_aws_config / load_yaml_profile_map

§Engineering invariants

  • #![forbid(unsafe_code)] at the crate root — no unsafe, ever.
  • No unwrap / expect / panic reachable 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 Debug impls 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::SharedProfileMap;
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 Workspace into resources.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 a Workspace.
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 a RawComponent.
parser
High-level Parser facade — 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.