Skip to main content

tfmate

Documentation: https://tfmate.readthedocs.org

tfmate is a command line interface and Python library for analyzing Terraform configurations and state files. It provides powerful tools for understanding your infrastructure as code, including configuration analysis, AWS service discovery, and state file inspection.

Features

  • Configuration Analysis: Analyze Terraform configuration files to understand providers, backends, and version constraints
  • AWS Service Discovery: List and filter AWS services from botocore definitions
  • State File Inspection: Extract Terraform version and metadata from state files
  • Multiple Output Formats: Support for JSON, table, and text output formats
  • Flexible Configuration: Customizable through configuration files and environment variables

Installation

tfmate supports Python 3.10+.

To install from PyPI:

pip install tfmate

To install using uv:

    sh -c "$(curl -fsSL https://astral.sh/uv/install)"
    uv tool install tfmate

Ensure you have ./local/bin in your PATH, since that's where uv puts the executable.

Quick Start

# Get help
tfmate --help

# Analyze Terraform configuration
tfmate analyze config

# List AWS services
tfmate aws services

# Get Terraform version from state
tfmate terraform version

# Recurse through all your .terraform folders and delete any unused provider or module code.
tfmate terraform prune-cache


# Use JSON output for scripting
tfmate --output json analyze config

Usage Examples

Analyze Terraform Configuration

# Analyze current directory
tfmate analyze config

# Analyze specific directory with detailed info
tfmate analyze config --directory ./infrastructure --show-providers --show-backend

# Output as JSON for scripting
tfmate --output json analyze config > config.json

AWS Service Discovery

# List all AWS services
tfmate aws services

# List only service names
tfmate aws services --names-only

# Filter services by pattern
tfmate aws services --filter-name "ec2*" --sort-by name

State File Operations

# Get Terraform version from state
tfmate terraform version

# Get version from specific directory
tfmate terraform version --directory ./infrastructure

# Use explicit state file (local only)
tfmate terraform version --state-file ./terraform.tfstate

Prune Stale Provider/Module Cache

# Recursively find .terraform cache directories and interactively prune stale
# provider versions and orphaned module checkouts left behind by
# `terraform init --upgrade`, comparing against .terraform.lock.hcl and
# modules.json
tfmate terraform prune-cache

# Preview what would be pruned without prompting or deleting anything
tfmate terraform prune-cache --dry-run

# Prune a specific directory tree
tfmate terraform prune-cache ./infrastructure

Documentation

For detailed documentation, visit: https://tfmate.readthedocs.org

Development

To set up a development environment:

# Clone the repository
git clone https://github.com/caltechads/tfmate.git
cd tfmate

uv sync
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Run tests
pytest

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

License

See LICENSE.txt in this project for the license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfmate-0.3.0.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tfmate-0.3.0-py3-none-any.whl (117.8 kB view details)

Uploaded Python 3

File details

Details for the file tfmate-0.3.0.tar.gz.

File metadata

  • Download URL: tfmate-0.3.0.tar.gz
  • Upload date:
  • Size: 54.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for tfmate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3025338ea0c15e410ea8748d13fa2230bc80447393d2a8f545f583a9b9e84253
MD5 7b7ffc0f6ebddec2e3e6b361b688cc47
BLAKE2b-256 9172905d8bb62b72583c63d6e0246d44edbfa96da93ee99a6b8e56272d45e552

See more details on using hashes here.

File details

Details for the file tfmate-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: tfmate-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 117.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for tfmate-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 148dd58c613698063ed23fc68d814349a21312b1bdbf07a608d9b264e39a0122
MD5 fe4444d1da6c5a6cb2ee8c109facaac3
BLAKE2b-256 47a5cc716dba9ccce2f76d825d06efb43a43e317d23a6d2c13310c8cf4de23f8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

This release

0.3.0 This release

2 files

0.2.1

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 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