Metadata-Version: 2.1
Name: sentinel-mock-plan
Version: 0.3.0
Summary: Create a mock plan for Hashicorp Sentinel 0.26.2
Author: Amine Laabi
Author-email: amine.laabi@outlook.fr
Requires-Python: >=3.12,<4.0
Classifier: Programming Language :: Python :: 3
Description-Content-Type: text/markdown

# Sentinel Mock Plan

This project creates a mock plan for **HashiCorp Sentinel 0.26.2** 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](#overview)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)

## 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.26.2. 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](https://www.terraform.io/) (to generate the plan file)
- HashiCorp Sentinel 0.26.2 (for testing with the generated mock plan)

## Installation

1. Install the package via `pip`:

   ```bash
   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:

   ```bash
   terraform init -reconfigure -backend-config=backends/dev.tfvars
   ```

2. Generate a Terraform plan:

   ```bash
   terraform plan -out=tf.plan -var-file=environments/dev.tfvars
   ```

3. Export the plan to a JSON format:

   ```bash
   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:

```bash
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:

```bash
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:

   ```bash
   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:

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

3. Use the generated mock plan in your Sentinel tests.

