PowerShell Module to Wrap Hcl2Json CLI tool for Easy distribution of PowerShell cmdlets to Parse HCL Files
Thanks to @tmccombs for the original CLI tool, you can see the original code of the CLI tool in below urls.
hcl2Json Project Url: https://github.com/tmccombs/hcl2json
hcl2Json Project License: https://github.com/tmccombs/hcl2json/blob/main/LICENSE
Hcl2PS
is aimed to be cross-platform and tested with best effort on Windows, Linux, and MacOS.
Getting started with Hcl2PS
is easy. Simply install and Import the module from the gallery using the following commands:
Install-Module -Name Hcl2PS
Import-Module -Name Hcl2PS
The cmdlet ConvertFrom-Hcl
accepts input in two ways, you can either pass a filepath to the Hcl file you wish to convert to a terraform object, or you can pass the contents of the file via pipeline input.
ConvertFrom-Hcl -Path .\main.tf
Get-Content .\main.tf -Raw | ConvertFrom-Hcl
As an output, the Cmdlet will return a Powershell object which has the properties mapped from the HCL syntax file's contents.
The cmdlet also supports a new -AsJson switch that allows you to return the output as a JSON string instead of a PowerShell object. This can be useful if you need to work with the data in JSON format or want to verify that the conversion to JSON is correct.
ConvertFrom-Hcl -Path .\main.tf -AsJson
Get-Content .\main.tf -Raw | ConvertFrom-Hcl -AsJson
When using the -AsJson switch, the Cmdlet will return a JSON string that represents the same data as the standard PowerShell object output.
These features provide flexibility in how you work with HCL files, allowing you to choose the output format that best suits your needs.
Contributions are welcomed, please raise a Pull Request with your proposed modifications if you wish to make any changes. If you find an Issue and wish to report it, please use the Issues section.
Apache Licensed, please see license for details.