Skip to content

A parser for HCL(HashiCorp Configuration Language) written in Erlang/Elixir.

Notifications You must be signed in to change notification settings

ilovemysillybanana/hclparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HCLParser

A package to read Terraform 0.12.0 into an elixir manageable data structure.

Usage

# get a string of code, whether its from you or a file

tf_code = '
    resource "google_compute_instance" "test1" {
      name         = "test"
      machine_type = "n1-standard-1"
      zone         = "us-central1-a"
      tags         = ["foo", "bar"]
      allow_stopping_for_update = true
      service_account {
        scopes = ["userinfo-email", "compute-ro", "storage-ro"]
      }
      metadata = {
        foo = "bar"
      }
    }

    resource "google_compute_instance" "test2" {
      name         = "test"
      machine_type = "n1-standard-1"
      zone         = "us-central1-a"
      tags         = ["foo", "bar"]
      allow_stopping_for_update = true
      service_account {
        scopes = ["userinfo-email", "compute-ro", "storage-ro"]
      }
      metadata = {
        foo = "bar"
      }
    }
    '
  HCLParser.parse(tf_code)

  # returns the following:
  ex(2)> HCLParser.parse(tf_code)
HCLParser.parse(tf_code)
{:ok,
 %{
   resource: %{
     "google_compute_instance" => %{
       "test1" => %{
         allow_stopping_for_update: true,
         machine_type: "n1-standard-1",
         metadata: %{foo: "bar"},
         name: "test",
         service_account: %{
           scopes: ["userinfo-email", "compute-ro", "storage-ro"]
         },
         tags: ["foo", "bar"],
         zone: "us-central1-a"
       },
       "test2" => %{
         allow_stopping_for_update: true,
         machine_type: "n1-standard-1",
         metadata: %{foo: "bar"},
         name: "test",
         service_account: %{
           scopes: ["userinfo-email", "compute-ro", "storage-ro"]
         },
         tags: ["foo", "bar"],
         zone: "us-central1-a"
       }
     }
   }
 }}

Installation

If available in Hex, the package can be installed by adding hclparser to your list of dependencies in mix.exs:

def deps do
  [
    {:hclparser, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/hclparser.

About

A parser for HCL(HashiCorp Configuration Language) written in Erlang/Elixir.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published