Registry / devops / tfstate-loves-mongo

tfstate-loves-mongo

JSON →
library1.2.3jsnpmunverified

A GitHub Action that manages Terraform state files using MongoDB as a backend. It automatically restores the latest tfstate snapshot before Terraform runs and saves the updated state after, keeping only the two most recent snapshots to prevent storage bloat. Version 1.2.3 is stable. Unlike S3 or Consul backends, this offers simple MongoDB-based state management directly in GitHub Actions workflows. It requires Node.js 24 and a MongoDB instance with read/write permissions.

npm install tfstate-loves-mongo
INSTALL
IMPORT
SIG · TFSTATE-LOVES-MONG
T
tfstate-loves-mongo
devopsjavascriptv1.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

action
uses: tsuji-riya/tfstate-loves-mongo@v1
import { action } from 'tfstate-loves-mongo'
This is a GitHub Action, not an npm package. Use 'uses' in workflow YAML.

Full workflow example showing checkout, mongo state management, and Terraform init/apply.

name: Example workflow on: [push] jobs: terraform: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: tsuji-riya/tfstate-loves-mongo@v1 with: mongo-uri: ${{ secrets.MONGO_URI }} - name: Setup Terraform uses: hashicorp/setup-terraform@v3 - run: terraform init - run: terraform apply -auto-approve
Debug
Known issues
gotchaEnsure mongo-uri is stored in a secret, not hard-coded.
fix
Store the MongoDB connection string in GitHub Actions secrets and reference it as ${{ secrets.MONGO_URI }}.
affects: >=1.0.0
gotchaMongoDB user must have read/write permissions on the target database and collection.
fix
Grant appropriate roles (e.g., readWrite) to the MongoDB user for the specified database.
affects: >=1.0.0
gotchaOnly the two most recent snapshots are kept; older state is automatically pruned.
fix
If you need more history, you must back up the MongoDB collection externally.
affects: >=1.0.0
gotchaNode.js 24 is required; using a different runner image may fail.
fix
Use a runner that supports Node.js 24 or specify 'runs-on: ubuntu-latest' which is compatible.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mongodb'
MongoDB driver not installed if using as npm package, but this is a GitHub Action so no npm install needed.
fix
Ensure you are using the action via 'uses' in workflow, not as a package.
Error: connect ECONNREFUSED mongodb://...
MongoDB URI is incorrect or network inaccessible.
fix
Verify the mongo-uri secret is correct and the MongoDB instance is reachable from GitHub Actions runners.
No tfstate found in database, continuing with empty state.
No prior snapshot exists; this is normal for first run.
fix
No action needed; it will create a snapshot after Terraform run.
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
tfstate-loves-mongo — npm install tfstate-loves-mongo · libregistry