ModPosh.Hcl 1.1.0

dotnet add package ModPosh.Hcl --version 1.1.0                
NuGet\Install-Package ModPosh.Hcl -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ModPosh.Hcl" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ModPosh.Hcl --version 1.1.0                
#r "nuget: ModPosh.Hcl, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ModPosh.Hcl as a Cake Addin
#addin nuget:?package=ModPosh.Hcl&version=1.1.0

// Install ModPosh.Hcl as a Cake Tool
#tool nuget:?package=ModPosh.Hcl&version=1.1.0                
Latest Version Nuget.org Issues Testing License Discord
Latest Version Nuget.org GitHub issues Merge Test Workflow GitHub license Discord Server

HCL Parser

Overview

The HCL Parser is a custom-built C# library designed to parse, manipulate, and generate HashiCorp Configuration Language (HCL) files. This parser plays a crucial role in the Terraform module update process by allowing structured modifications to variables.tf, main.tf, and other HCL files. The library provides an object-oriented representation of HCL, enabling easy transformations and validation before updating Terraform modules.

Features

  • HCL Parsing: Converts HCL into structured objects that can be programmatically modified.
  • Object-Oriented Representation: Defines HCL elements as discrete C# objects with overridable methods.
  • HCL Generation: Converts modified objects back into valid HCL strings.
  • PowerShell Compatibility: Can be integrated into a PowerShell module for automation in CI/CD pipelines.

Installation

The HCL Parser can be added to a .NET project via NuGet:

dotnet add package ModPosh.HclParser

Alternatively, if using an internal feed:

dotnet nuget add source <internal_feed_url>
dotnet add package ModPosh.HclParser --source <internal_feed>

Usage

Parsing HCL

using ModPosh.HclParser;

string hclText = @"variable \"instance_count\" {\n  type = number\n  default = 1\n}";

HclDocument doc = HclParser.Parse(hclText);
foreach (var variable in doc.Variables)
{
    Console.WriteLine($"Variable: {variable.Name}, Default: {variable.Default}");
}

Modifying HCL

HclVariable variable = new HclVariable("instance_type")
{
    Type = "string",
    Default = "n1-standard-1"
};

HclDocument doc = new HclDocument();
doc.Add(variable);

string outputHcl = doc.ToString();
Console.WriteLine(outputHcl);

Future Enhancements

  • Support for HCL2 with nested blocks and expressions.
  • Integration with Azure DevOps for automated module updates.
  • Additional validation rules to detect deprecated or incorrect configurations.

Contributing

Contributions are welcome! Please follow the contribution guidelines and submit a pull request.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 60 2/12/2025
1.0.0 84 2/7/2025