Skip to main content

Create a mock plan for Hashicorp Sentinel from 0.26.2 to 0.40.0

Project description

Sentinel Mock Plan

This project creates a mock plan for HashiCorp Sentinel 0.40.0 using a JSON plan file generated by Terraform. It converts the plan file into a format that can be used in Sentinel policies for testing and validation.

Table of Contents

Overview

This project provides a Python utility that processes a JSON plan file (produced by Terraform) and converts it into a mock plan file compatible with HashiCorp Sentinel 0.40.0. The generated mock plan is useful for simulating infrastructure changes and running Sentinel policies without applying actual changes to cloud infrastructure.

Features:

  • Converts a JSON Terraform plan into a mock Sentinel plan.
  • Customizable input and output file options.
  • Supports overwriting existing output files.

Prerequisites

  • Python 3.8+
  • Terraform (to generate the plan file)
  • HashiCorp Sentinel 0.40.0 (for testing with the generated mock plan)

Installation

  1. Install the package via pip:

    pip install sentinel-mock-plan
    

Usage

To use this utility, first generate the Terraform plan JSON file and then run the Python script to convert it.

Generating the JSON Plan

  1. Initialize Terraform with the desired backend configuration:

    terraform init -reconfigure -backend-config=backends/dev.tfvars
    
  2. Generate a Terraform plan:

    terraform plan -out=tf.plan -var-file=environments/dev.tfvars
    
  3. Export the plan to a JSON format:

    terraform show -no-color -json tf.plan > plan.json
    

Converting the JSON Plan to a Sentinel Mock Plan

Now, run the Python utility to convert the plan.json file into a mock Sentinel plan:

python -m sentinel_mock_plan --infile plan.json --outfile mock-tfplan-v2.sentinel

Options:

  • --infile: Input file name (default: plan.json)
  • --outfile: Output file name (default: mock-tfplan-v2.sentinel)
  • --overwrite: Overwrite the output file if it exists

Example:

python -m sentinel_mock_plan --infile plan.json --outfile mock-tfplan-v2.sentinel --overwrite

This will generate a mock plan file named mock-tfplan-v2.sentinel from the plan.json input.

Example Workflow

  1. Run Terraform commands:

    terraform init -reconfigure -backend-config=backends/dev.tfvars
    terraform plan -out=tf.plan -var-file=environments/dev.tfvars
    terraform show -no-color -json tf.plan > plan.json
    
  2. Convert the JSON plan to a mock Sentinel plan:

    python -m sentinel_mock_plan --infile plan.json --outfile mock-tfplan-v2.sentinel
    
  3. Use the generated mock plan in your Sentinel tests.

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

sentine_mock_plan-0.4.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

sentine_mock_plan-0.4.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file sentine_mock_plan-0.4.0.tar.gz.

File metadata

  • Download URL: sentine_mock_plan-0.4.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.18 Linux/6.11.0-1018-azure

File hashes

Hashes for sentine_mock_plan-0.4.0.tar.gz
Algorithm Hash digest
SHA256 58f4bee32f8588ebc3db7b57f067e3b1b94137a6432988b2de16f5f6095264c1
MD5 fbc3660f8ece486adaff00f1d27caa96
BLAKE2b-256 aeab9e869377663b7d0c9ffb3694a5e82fb7130c646847d4d719e80b7c33338e

See more details on using hashes here.

File details

Details for the file sentine_mock_plan-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: sentine_mock_plan-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.18 Linux/6.11.0-1018-azure

File hashes

Hashes for sentine_mock_plan-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a898c941223642c31df48890ce2931a383f2606532b593b70b275f35762c0590
MD5 89ce8bd3dd8db617fc7f535606112e5b
BLAKE2b-256 633111f3769ae70d4bc97c9ed195f80aa13fa3c32af90faba33c761eeb9ca16e

See more details on using hashes here.

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