hcledit command

hcledit
command is a CLI tool to edit HCL configuration, which exposes hcledit
API as command line interface. You can think this as a sample application built by the package.
Install
Install binaries via GitHub Releases or below:
Homebrew:
$ brew tap mercari/hcledit https://github.com/mercari/hcledit
$ brew install hcledit
go get
:
$ go get -u go.mercari.io/hcledit/cmd/hcledit
Docker:
$ docker run --rm -it mercari/hcledit hcledit
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 read an attribute,
$ hcledit read 'resource.google_container_node_pool.*.node_config.machine_type' /path/to/file.tf
resource.google_container_node_pool.nodes1.node_config.machine_type e2-medium
To create a new attribute,
$ hcledit create 'resource.google_container_node_pool.*.node_config.image_type' 'COS' /path/to/file.tf
resource "google_container_node_pool" "nodes1" {
name = "nodes1"
node_config {
preemptible = false
machine_type = "e2-medium"
+ image_type = "COS"
}
}
To update the existing attribute,
$ hcledit update 'resource.google_container_node_pool.*.node_config.machine_type' 'e2-highmem-2' /path/to/file.tf
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,
$ hcledit delete 'resource.google_container_node_pool.*.node_config.machine_type' /path/to/file.tf
resource "google_container_node_pool" "nodes1" {
name = "nodes1"
node_config {
preemptible = false
- machine_type = "e2-medium"
}
}