hcl2json

A high-performance CLI tool for converting Terraform HCL files to JSON format, designed for seamless integration with TerraForce CI/CD pipelines to enforce security policies

Download Now Get Started

Features

High Performance

Concurrent processing with configurable goroutines for optimal conversion speed

🔄

CI/CD Integration

Seamless integration with GitHub Actions, GitLab CI, Jenkins, and other CI/CD platforms

🔍

Terraform Support

Full support for *.tf and *.tfvars files with detailed error reporting

🔗

TerraForce Ready

Designed to work seamlessly with TerraForce in your IaC security pipeline

Downloads

Choose the right version for your platform

Linux Binaries

macOS Binaries

Docker Images

Usage

% hcl2json
 _          _ ____   _                 
| |__   ___| |___ \ (_)___  ___  _ __  
| '_ \ / __| | __) || / __|/ _ \| '_ \ 
| | | | (__| |/ __/ | \__ \ (_) | | | |
|_| |_|\___|_|_____|/ |___/\___/|_| |_|
                    |__/                 

Scan directories for Terraform HCL files and convert to JSON
------------------------------------------------------------
author: Henry Bravo | date: January 2025 | version: 1.0.0

Usage:
    hcl2json [flags]
    hcl2json [command]

Available Commands:
    completion  Generate the autocompletion script for the specified shell
    help        Help about any command
    version     Print the version number of hcl2json

Flags:
    -d, --debug                 Enable debug mode
    -D, --directory string      Specify the directory to scan
    -h, --help                  help for hcl2json
    -m, --max-concurrency int   Maximum number of concurrent goroutines (default 10)
    -r, --recursive             Scan subdirectories recursively

Basic Usage

hcl2json --directory /path/to/terraform/files --recursive

CI/CD Pipeline Integration

# GitHub Actions Example
name: Terraform Security Scan
on: [push, pull_request]

jobs:
  security-scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      
      - name: Convert HCL to JSON
        run: |
          hcl2json --directory . --recursive --debug
          
      - name: Run TerraForce Scan
        run: |
          terraforce pre-plan policy.yml main.tf.json

Example Input main.tf

resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  tags = {
    Name = "example-instance"
    Environment = "production"
  }
}

Example Output main.tf.json

{
  "resource": {
    "aws_instance": {
      "example": {
        "ami": "ami-12345678",
        "instance_type": "t2.micro",
        "tags": {
          "Name": "example-instance",
          "Environment": "production"
        }
      }
    }
  }
}

Changelog

Version 1.0.0

Initial Release

  • Initial release with concurrent HCL to JSON conversion
  • Support for *.tf and *.tfvars files
  • Integration with CI/CD pipelines (GitHub Actions, GitLab CI, Jenkins)
  • Detailed error reporting and debug mode
  • Recursive directory scanning
  • Configurable concurrency settings
  • Docker support with multi-arch images
  • TerraForce integration capabilities
Version 0.9.0-beta

Beta Release

  • Initial implementation of HCL parsing engine
  • Basic JSON conversion functionality
  • Command-line interface implementation
  • Performance testing and optimization
  • Documentation and usage examples

Roadmap

Future Releases

  • Enhanced support for HCL2 complex types and expressions
  • Built-in validation of Terraform configuration syntax
  • Support for custom output formatting options
  • Integration with additional CI/CD platforms
  • Performance optimizations for large-scale Terraform configurations
  • Native GitHub Actions and GitLab CI integration packages
  • Extended TerraForce integration features
  • Support for Terraform Enterprise workspace integration

Disclaimer

This notice is to clarify the relationship between hcl2json, developed by Henry Bravo, and HashiCorp (https://www.hashicorp.com).

Independence Statement

Key Points

Trademark Notice

HashiCorp, Terraform, and HCL are registered trademarks of HashiCorp, Inc. The use of these terms in this notice does not imply any endorsement or affiliation.

Contact Information

For any inquiries, support requests, or feedback regarding hcl2json, please contact Henry directly: