Skip to main content

tf2okf

tf2okf generates deterministic Open Knowledge Format v0.2 Markdown from Terraform-family repositories.

Install and run

Requires Python 3.10 or newer.

Install from this repository (local source)

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
python3 -m pip install .
tf2okf --help

Install for use in other repositories

Install once, then run tf2okf from any Terraform/Terragrunt project.

If published on PyPI:

python3 -m pip install tf2okf

If not published on PyPI, install directly from Git:

python3 -m pip install "git+https://github.com/<owner>/tf2okf.git"

For isolated global CLI usage across projects (pipx):

pipx install "git+https://github.com/<owner>/tf2okf.git"

Common commands:

tf2okf frameworks
tf2okf discover .
tf2okf init .
tf2okf generate .
tf2okf check .
tf2okf diff .

Generation profiles and optional AI summaries:

# Smaller machine output (fewer heavy files, compact interfaces)
tf2okf generate . --profile compact

# Full output (default)
tf2okf generate . --profile full

# Optional AI summary generation
tf2okf generate . --include-ai --ai-provider ollama --ai-model llama3.1:8b
tf2okf generate . --include-ai --ai-provider claude --ai-model claude-3-5-haiku-latest
tf2okf generate . --include-ai --ai-provider openai --ai-model gpt-4.1-mini

Authentication:

  • ollama - no API key; local server, default http://127.0.0.1:11434
  • claude - set ANTHROPIC_API_KEY
  • openai - set OPENAI_API_KEY

Framework selection

tf2okf frameworks
tf2okf discover .
tf2okf init . --framework auto
tf2okf init . --framework tfscaffold
tf2okf init . --framework terragrunt
tf2okf init . --framework plain-terraform

Configuration:

version: '2'
framework:
  type: auto
generation:
  profile: full   # full | compact
ai:
  enabled: false
  provider: ollama
  output_dir: generated/ai
  ollama:
    base_url: http://127.0.0.1:11434
    model: llama3.1:8b
    timeout_seconds: 30
  claude:
    base_url: https://api.anthropic.com
    model: claude-3-5-haiku-latest
    api_key_env: ANTHROPIC_API_KEY
    timeout_seconds: 60
  openai:
    base_url: https://api.openai.com/v1
    model: gpt-4.1-mini
    api_key_env: OPENAI_API_KEY
    timeout_seconds: 60

auto detects known framework signatures. Explicit selection always wins.

tfscaffold adapter

Discovers independent components/, reusable modules/, and etc/*.tfvars environment metadata. Each generated component page includes a preserved Component description block between tf2okf:manual-description-start and tf2okf:manual-description-end; edit only that block to keep your explanation through regeneration.

Terragrunt adapter

Discovers each terragrunt.hcl unit, static terraform.source, include, dependency.config_path, shared HCL and terragrunt.stack.hcl files. .terragrunt-cache and generated .terragrunt-stack content are ignored.

Plain Terraform adapter

Parses Terraform source directly from the configured root.

Curated knowledge examples

The generated bundle keeps human-written context under .okf/knowledge/. Typical starting points:

architecture.md

---
type: Architecture Knowledge
title: Architecture
description: Human-curated architecture and design intent.
tags:
  - architecture
  - manual
---

# Architecture

## System purpose

This repository provisions the shared network, security, and application runtime for the platform.

## Main building blocks

- `components/network` creates the VPC and shared subnets.
- `components/security` creates ALB and application security groups.
- `components/app` deploys the ECS service behind the ALB.

## Important boundaries

- Each `components/` directory is an independent state boundary.
- Shared modules under `modules/` must stay reusable and environment-agnostic.

## Design rules

- Network outputs are consumed by security and application layers.
- Security outputs are consumed by application components.
- Manual architectural decisions belong here, not in generated files.

security.md

---
type: Security Knowledge
title: Security
description: Human-curated security constraints and rationale.
tags:
  - security
  - manual
---

# Security

## Security goals

- Prevent public access to private workloads.
- Keep secrets out of generated OKF and committed source.
- Make network exposure explicit at component boundaries.

## Required controls

- Only ALB-facing security groups may allow internet ingress.
- Application tasks must run in private subnets.
- Sensitive Terraform inputs and outputs must be redacted in generated docs.

## Operational expectations

- Review `.okf/generated/topology.md` after infrastructure changes.
- Regenerate OKF after changing inputs, outputs, dependencies, or module composition.
- Treat Terraform source as the implementation source of truth when curated knowledge and generated knowledge diverge.

Commands

  • init — create configuration, detect/select framework, create initial OKF and Copilot instructions
  • discover — show detected framework and reasons without changing files
  • generate — regenerate machine-owned OKF
  • generate --include-ai --ai-provider ... — add optional AI summaries using Ollama, Claude, or OpenAI
  • check — fail when committed generated OKF has drifted
  • diff — show generated knowledge diff
  • frameworks — list supported adapters

No LLM is required for deterministic OKF generation. AI summaries are optional and only used when --include-ai or ai.enabled: true is set.

Security defaults

tf2okf is intentionally source-only: it does not read Terraform state, plans, cloud credentials, or execute Terraform. Repository-relative configuration paths are containment-checked; symlinked Terraform files are ignored; source files over 2 MiB are skipped; likely secret-bearing attributes are redacted; and optional terraform-docs execution has a timeout and captured-output limit. See SECURITY.md for the threat model.

Open-source release checklist

Before publishing: enable GitHub private vulnerability reporting, branch protection/rulesets, required CI/CodeQL/dependency review checks, Dependabot security updates, secret scanning/push protection where available, and PyPI trusted publishing for the pypi environment. Run python -m build && python -m twine check dist/* locally or in CI. See docs/pypi-release.md for the workflow and setup details.

Metadata

Release files for tf2okf 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tf2okf 0.10.0
File Size Uploaded
tf2okf-0.10.0.tar.gz 43.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tf2okf 0.10.0
File Interpreter ABI Platform
tf2okf-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 85.4 kB

Release files / tf2okf-0.10.0.tar.gz

Download URL tf2okf-0.10.0.tar.gz
Size 43.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b70b1d9cbed8affa37043d04479b0c32b4d12df98db7edc4f7c9455628cf36db
BLAKE2b-256 checksum
How to use checksums
fe0a343d203ce458c83ff92203a23412ae1b8aa1c4ffa79dd481560531101f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / tf2okf-0.10.0-py3-none-any.whl

Download URL tf2okf-0.10.0-py3-none-any.whl
Size 42.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
090afa1249063370a0d98cd84d8bcb91980fa858a7fc341fbc164253f57c0c60
BLAKE2b-256 checksum
How to use checksums
b28c58157cd40c1008c4dff30fb8870803108a2eff2e30dfddcfb4bae7bd0cf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.0

2 release files

This release

0.10.0 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page