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.
Use go install
:
$ go install go.mercari.io/hcledit/cmd/hcledit@latest
See Go doc.
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"
}
}
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.
The hcledit is released under the MIT License.