Skip to content

jordanst3wart/hcl

Repository files navigation

Hcl

A jdk library to parse, and write HCL variable files (or tfvar files). HCL is a configuration language used by HashiCorp tools like Terraform, Consul, Packer, and Vault. This does not support HCL variables, but just hcl variable files. ie. no support for resource blocks

Installation

build.gradle.kts

implementation("bot.stewart:hcl:0.2.0")

build.gradle

implementation 'bot.stewart:hcl:0.2.0'

maven pom

<dependency>
    <groupId>bot.stewart</groupId>
    <artifactId>hcl</artifactId>
    <version>0.2.0</version>
</dependency>

Usage

Parsing

String hcl = "region = {\n  default = \"us-west-1\"\n};
HclParser parser = new HclParser();
Map<String, Any> variables = parser.parse(hcl);

Writing

Map<String, Any> variables = new HashMap<>();
variables.put("region", Map.of("default", "us-west-1"));
String hcl = Hcl.write(variables);

Support

  • Parsing HCL variables (except indented heredoc strings)
  • Writing HCL variables
  • Writing from POJOs to tfvars
  • Marshalling to POJOs
  • streaming string inputs, and outputs (for large files)

Doesn't aim to look reading for_each loops, modules, or variable substitution.

Spec

The HCL spec (alhtough not formal) is here: https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md

License

MIT license

Miscellanous

If you don't want to add a dependency this library is currently just two kotlin files. You can copy them into your project. This library has no dependencies.

About

A hcl parser and writer for tfvar files

Resources

License

Stars

Watchers

Forks

Contributors