Code Monkey home page Code Monkey logo

hcleditm's Introduction

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.

hcleditm's People

Contributors

micnncim avatar tcnksm avatar drlau avatar dependabot[bot] avatar keisukeyamashita avatar goreleaserbot avatar slewiskelly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.