@infodb/tfme
v0.2.0
Published
Terraform schema to YAML conversion and documentation download
Readme
tfme
Terraform provider schema converter and documentation downloader.
Features
- YAML Export: Export specific Terraform resource schema to YAML format (simple conversion, no transformations)
- Markdown Download: Download specific resource documentation from Terraform Registry API
- Auto Provider Detection: Automatically detect provider name from resource name (e.g.,
aws_vpc→aws) - GitHub Integration: Automatically download provider schemas from GitHub repository
- Local Cache: Cache downloaded schemas in
~/.tfme/cache/for faster access
Installation
# Install globally
npm install -g @infodb/tfme
# Or use with pnpx
pnpx @infodb/tfme
# Or install locally and build
cd tfme
pnpm install
pnpm run buildQuick Start
Export Resource Schema to YAML
# Export resource schema (provider auto-detected from resource name)
pnpx @infodb/tfme export -r aws_vpc -o output
# Clear cache and download fresh schema
pnpx @infodb/tfme export -r aws_vpc --clear-cache -o outputDownload Resource Documentation
# Download resource documentation (provider auto-detected)
pnpx @infodb/tfme download -r aws_vpc -o docs
# With specific version
pnpx @infodb/tfme download -r aws_vpc -v 5.0.0 -o docsCommand Reference
export Command
Export Terraform resource schema to YAML format.
tfme export [options]Options:
-r, --resource <resource>(required): Resource name (e.g., aws_vpc)-o, --output <dir>: Output directory (default: "output")--clear-cache: Clear cache before downloading
Examples:
# Export resource schema (provider auto-detected)
pnpx @infodb/tfme export -r aws_vpc -o output
# Export with cache clearing
pnpx @infodb/tfme export -r azurerm_virtual_network --clear-cache -o outputdownload Command
Download Markdown documentation from Terraform Registry.
tfme download [options]Options:
-r, --resource <resource>(required): Resource name (e.g., aws_vpc)-o, --output <dir>: Output directory (default: "docs")-n, --namespace <namespace>: Provider namespace (default: hashicorp)-v, --version <version>: Provider version (default: latest)
Examples:
# Download resource documentation (provider auto-detected)
pnpx @infodb/tfme download -r aws_vpc -o docs
# Download with specific version
pnpx @infodb/tfme download -r aws_s3_bucket -v 5.0.0 -o docs
# Download with custom namespace
pnpx @infodb/tfme download -r aws_vpc -n hashicorp -o docsSchema Generation (for Repository Maintainers)
Provider schemas are stored in this repository under schemas/providers/. To generate new schemas:
cd schemas/scripts
./generate-schemas.shThis script:
- Initializes Terraform for each provider (aws, azurerm, google)
- Generates schema JSON for each provider
- Saves to
schemas/providers/{provider}.json
Output Format
YAML Export
The export command extracts the specified resource schema and converts it to YAML format:
version: 1
block:
attributes:
arn:
type: string
description_kind: plain
computed: true
cidr_block:
type: string
description_kind: plain
optional: true
computed: true
enable_dns_support:
type: bool
description_kind: plain
optional: trueMarkdown Documentation
Downloaded documentation is in standard Terraform documentation format:
---
subcategory: "VPC (Virtual Private Cloud)"
layout: "aws"
page_title: "AWS: aws_vpc"
---
# Resource: aws_vpc
Provides a VPC resource.
## Example Usage
...Cache Directory
Downloaded schemas are cached in ~/.tfme/cache/ to improve performance:
~/.tfme/
└── cache/
├── aws.json
├── azurerm.json
└── google.jsonClear cache with --clear-cache flag or manually delete files.
Development
# Install dependencies
pnpm install
# Build
pnpm run build
# Watch mode
pnpm run dev
# Run CLI
pnpm run start export -r aws_vpc -o output
pnpm run start download -r aws_vpc -o docsProject Structure
tfme/
├── bin/cli.js # CLI entry point
├── src/
│ ├── index.ts # Main CLI setup
│ ├── commands/
│ │ ├── export.ts # Export command
│ │ └── download.ts # Download command
│ └── utils/
│ ├── converter.ts # JSON to YAML converter
│ ├── schema-fetcher.ts # GitHub schema fetcher with cache
│ └── registry-client.ts # Terraform Registry API client
└── schemas/
├── terraform/ # Terraform configurations per provider
│ ├── aws/
│ ├── azurerm/
│ └── google/
├── providers/ # Generated schema JSON files
└── scripts/
└── generate-schemas.shLicense
MIT
