Skip to content
forked from mercari/hcledit

Go package to edit HCL configuration

License

Notifications You must be signed in to change notification settings

ryan-ph/hcledit

 
 

Repository files navigation

hcledit

workflow-test release pkg.go.dev license

hcledit is a wrapper around the hclwrite package that adds the ability to edit and manipulate HCL documents using a jq-like query/selector syntax.

We provide a Go package and a simple CLI application based on this package. See hcledit command.

NOTE: This is still under heavy development and we don't have enough documentation and we are planing to add breaking changes. Please be careful when using it.

Install

Use go get:

$ go get -u go.mercari.io/hcledit

Usage

See Go doc.

Examples

The following is an HCL configuration which we want to manipulate.

resource "google_container_node_pool" "nodes1" {
   name = "nodes1"

   node_config {
     preemptible  = false
     machine_type = "e2-medium"
   }
}

To create a new attribute,

editor, _ := hcledit.ReadFile(filename)
editor.Create("resource.google_container_node_pool.*.node_config.image_type", "COS")
editor.OverWriteFile()
resource "google_container_node_pool" "nodes1" {
   name = "nodes1"

   node_config {
     preemptible  = false
     machine_type = "e2-medium"
+    image_type   = "COS"
   }
}

To update the existing attribute,

editor, _ := hcledit.ReadFile(filename)
editor.Update("resource.google_container_node_pool.*.node_config.machine_type", "e2-highmem-2")
editor.OverWriteFile()
resource "google_container_node_pool" "nodes1" {
   name = "nodes1"

   node_config {
     preemptible  = false
-    machine_type = "e2-medium"
+    machine_type = "e2-highmem-2"
   }
}

To delete the existing attribute,

editor, _ := hcledit.ReadFile(filename)
editor.Delete("resource.google_container_node_pool.*.node_config.machine_type")
editor.OverWriteFile()
resource "google_container_node_pool" "nodes1" {
   name = "nodes1"

   node_config {
     preemptible  = false
-    machine_type = "e2-medium"
   }
}

Contribution

During the active development, we unlikely accept PRs for new features but welcome bug fixes and documentation. If you find issues, please submit an issue first.

If you want to submit a PR for bug fixes or documentation, please read the CONTRIBUTING.md and follow the instruction beforehand.

License

The hcledit is released under the MIT License.

About

Go package to edit HCL configuration

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 97.6%
  • Ruby 1.3%
  • Other 1.1%