Skip to main content

A CLI tool to cache and serve Terraform provider registry responses

Project description

Terraform Registry Stub

A CLI tool to cache and serve Terraform Provider registry responses for offline or air-gapped environments.

Requirements: Python 3.11 or later

Features

  • 🚀 Cache providers from upstream Terraform Registry
  • 📦 Download provider packages (.zip files, checksums, signatures)
  • 🌐 Serve cached responses via local HTTP server
  • Fast parallel downloads using async HTTP client
  • 🎨 Beautiful progress bars powered by Rich
  • GPG signature verification for security
  • 📝 YAML manifest for easy configuration
  • 🔍 Version constraints using Terraform syntax

Installation

Using uv (recommended)

# Clone the repository
git clone https://github.com/TheLonelyGhost/terraform-registry-stub.git
cd terraform-registry-stub

# Create virtual environment and install
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e .

Using pip

pip install -e .

Quick Start

1. Create a manifest file

Create manifest.yaml:

registry: registry.terraform.io

providers:
  - namespace: hashicorp
    type: aws
    version_constraints:
      - ">= 5.0.0, < 5.10.0"
    platforms:
      - os: linux
        arch: amd64
      - os: darwin
        arch: arm64
    max_versions: 10
  
  - namespace: hashicorp
    type: random
    version_constraints:
      - "latest"
    platforms: ["*"]

cache_options:
  download_packages: true
  verify_signatures: true

2. Cache providers

# Using installed command
terraform-registry-stub cache --manifest manifest.yaml --output ./cache

# Or using python -m
python3 -m terraform_registry_stub cache --manifest manifest.yaml --output ./cache

3. Serve cached registry

# Using installed command
terraform-registry-stub serve --cache ./cache --port 8080

# Or using python -m
python3 -m terraform_registry_stub serve --cache ./cache --port 8080

4. Configure Terraform

Create or edit ~/.terraformrc:

provider_installation {
  direct {
    exclude = ["registry.terraform.io/*/*"]
  }
  network_mirror {
    url = "http://localhost:8080/"
  }
}

Usage

Both commands can be invoked using the installed command or via python3 -m:

# Using installed command
terraform-registry-stub cache -m manifest.yaml -o ./cache

# Or using python -m (useful when not in PATH)
python3 -m terraform_registry_stub cache -m manifest.yaml -o ./cache

Cache Command

terraform-registry-stub cache [OPTIONS]
# or: python3 -m terraform_registry_stub cache [OPTIONS]

Options:
  -m, --manifest PATH    Path to manifest YAML file [required]
  -o, --output PATH      Output directory for cache [default: ./cache]
  --no-packages          Skip downloading provider packages
  -p, --parallel INT     Number of concurrent downloads [default: 4]
  --force                Force re-download even if cached
  -h, --help             Show this message and exit

Serve Command

terraform-registry-stub serve [OPTIONS]
# or: python3 -m terraform_registry_stub serve [OPTIONS]

Options:
  -c, --cache PATH       Cache directory [default: ./cache]
  --host TEXT            Bind address [default: 127.0.0.1]
  -p, --port INT         Port number [default: 8080]
  --proxy-missing        Proxy uncached requests to upstream
  --reload               Enable auto-reload for development
  -h, --help             Show this message and exit

Manifest Format

Version Constraints

Use Terraform's version constraint syntax:

  • = 1.0.0 - Exact version
  • != 1.0.0 - Exclude version
  • > 1.0.0, >= 1.0.0 - Greater than (or equal)
  • < 1.0.0, <= 1.0.0 - Less than (or equal)
  • ~> 1.0 - Pessimistic constraint (>= 1.0, < 2.0)
  • ~> 1.0.0 - Pessimistic constraint (>= 1.0.0, < 1.1.0)
  • Multiple constraints: >= 1.0.0, < 2.0.0

Special Keywords

  • latest - Only cache the newest version
  • * - Cache all available versions

Example Manifest

registry: registry.terraform.io

providers:
  # Cache a range of versions
  - namespace: hashicorp
    type: aws
    version_constraints:
      - ">= 5.0.0, < 5.10.0"
      - "~> 5.20.0"  # OR logic: also include 5.20.x
    platforms:
      - os: linux
        arch: amd64
    max_versions: 10  # Limit to 10 newest
    include_prerelease: false

  # Cache latest version only
  - namespace: hashicorp
    type: random
    version_constraints:
      - "latest"
    platforms: ["*"]  # All available platforms

  # Cache all versions (with limit)
  - namespace: hashicorp
    type: null
    version_constraints:
      - "*"
    platforms:
      - os: linux
        arch: amd64
    max_versions: 20  # Safety limit

cache_options:
  download_packages: true   # Download .zip files
  verify_signatures: true   # Verify GPG signatures

Development

Setup development environment

# Install with dev dependencies
uv pip install -e ".[dev]"

Run tests

uv run pytest

Lint and format code

# Format code with ruff
uv run ruff format src/ tests/

# Check formatting without modifying files
uv run ruff format --check src/ tests/

# Lint and auto-fix with ruff
uv run ruff check --fix src/ tests/

# Check without auto-fixing
uv run ruff check src/ tests/

License

MIT License - see LICENSE file for details.

Project details


Download files

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

Source Distribution

terraform_registry_stub-0.1.0.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

terraform_registry_stub-0.1.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file terraform_registry_stub-0.1.0.tar.gz.

File metadata

  • Download URL: terraform_registry_stub-0.1.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for terraform_registry_stub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6e269cd8748632b313aff1567a939542498bbf9c4f71a3c3273a45c819ce6a34
MD5 7dc15f41faa5ffcf6734aa2e9dd284d6
BLAKE2b-256 ef5b999cce50d83fa8d8600d98a7c66fd7dbf909dfff43f2fd4bf048caf6d65f

See more details on using hashes here.

Provenance

The following attestation bundles were made for terraform_registry_stub-0.1.0.tar.gz:

Publisher: pypi.yml on TheLonelyGhost/terraform-registry-stub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file terraform_registry_stub-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for terraform_registry_stub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ec50d4f4c81ce7d70ea8b02787cde2e5f4064b8ff0988227159bdee541c6269
MD5 bd10e20adb293c6e3e9fe4790aec5388
BLAKE2b-256 f05d282413b7ebc07c820a7b8e5bfd0823571206f4f510d287724de7822859de

See more details on using hashes here.

Provenance

The following attestation bundles were made for terraform_registry_stub-0.1.0-py3-none-any.whl:

Publisher: pypi.yml on TheLonelyGhost/terraform-registry-stub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page