Giter VIP home page Giter VIP logo

hcl2ps's Introduction

.github/workflows/ci_pwsh.yml.github/workflows/ci_powershell.ymlpublish-modulevalidate-module-install
LicenseGitHub versionpowershellgallerydownloads

Hcl2PS

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

Installation

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

Usage

Standard Usage - PowerShell Object Output

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.

Examples

JSON String Output

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.

Examples

Contributions & Issues

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.

License

Apache Licensed, please see license for details.

hcl2ps's People

Contributors

mertsenel avatar

Stargazers

Christoph Vollmann avatar Dominika Sikorska avatar Ryan Butler avatar  avatar Jonathan Østrup avatar Jimmy Briggs avatar René avatar

Watchers

 avatar Dominika Sikorska avatar

Forkers

icornett

hcl2ps's Issues

GO version critical CVEs

Based on a scan we did on the image, it looks like the GO version used in the binaries is vulnerable.

CVE-2023-39320 and CVE-2023-39323
Path: /0.5.0/bin/0.6.0/hcl2json_linux_arm64

Recommended course of action: Upgrade GO to 1.21.2 or higher

Unable to run / import

Hello,

I tried to run version 0.2.0 but ran into two problems:

Getting the help text in the PowerShell ISE fails:

> Import-Module Hcl2PS
Get-ChildItem : Cannot find path 'C:\Program Files\WindowsPowerShell\Modules\Hcl2PS\0.2.0\Private' because it does not exist. 

That's happening because there is no Private folder:

C:\Program Files\WindowsPowerShell\Modules\Hcl2PS\0.2.0>tree
Folder PATH listing
Volume serial number is B657-1BD1
C:.
├───.github
│   └───workflows
├───bin
│   └───0.5.0
├───media
├───Public
└───__tests__
    └───testData

That's probably due to:

Hcl2PS/Hcl2PS.psm1

Lines 3 to 5 in d3634be

foreach ($directory in @('Public', 'Private')) {
Get-ChildItem -Path "$PSScriptRoot\$directory\*.ps1" | ForEach-Object { . $_.FullName }
}

The other problem is that platform detection fails because $IsWindows is not set on my Windows 10 PowerShell:

 PS C:\Users\gregor.jasny\Documents\SGmapping> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      19041  2364    


PS C:\Users\gregor.jasny\Documents\SGmapping> cmd ver
Microsoft Windows [Version 10.0.19044.2486]
(c) Microsoft Corporation. All rights reserved. 

Thanks,
Gregor

Invalid variable "type" after conversion from HCL

Hi, this is a great tool and it works beautifully to allow editing of HCL as objects in PowerShell.

However, I'm encountering an issue when validating the generated json with packer.

For example, if this variable is defined in the source HCL:

variable "tenant_id" {
  type    = string
  default = "${env("ARM_TENANT_ID")}"
}

The Hcl2PS module converts this to:

"tenant_id": [
    {
        "default": "${env(\"ARM_TENANT_ID\")}",
        "type": "${string}"
    }
]

Then, when running packer validate: packer validate .\windows.pkr.json

Error: Invalid type specification

  on .\windows.pkr.json line 479, in variable.tenant_id[0]:
 479:                 "type": "${string}"

A type specification is either a primitive type keyword (bool, number, string)
or a complex type constructor call, like list(string).

Changing it to simply "type": "string" fixes this and validates successfully. However, this is a problem for every type including map(string), bool, list(string), and the list goes on. It appears to always be wrapping the original type specified in the HCL as ${value}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.