Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rjeczalik/refmt
Reformat HCL ⇄ JSON ⇄ YAML.
https://github.com/rjeczalik/refmt
hcl json kubectl terraform yaml
Last synced: about 2 months ago
JSON representation
Reformat HCL ⇄ JSON ⇄ YAML.
- Host: GitHub
- URL: https://github.com/rjeczalik/refmt
- Owner: rjeczalik
- License: agpl-3.0
- Created: 2017-06-04T08:53:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-08T01:28:17.000Z (over 2 years ago)
- Last Synced: 2024-10-06T17:36:40.398Z (3 months ago)
- Topics: hcl, json, kubectl, terraform, yaml
- Language: Go
- Homepage: https://rafal.dev/refmt
- Size: 196 KB
- Stars: 25
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# refmt [![GoDoc](https://godoc.org/github.com/rjeczalik/refmt?status.png)](https://godoc.org/github.com/rjeczalik/refmt) [![Build Status](https://img.shields.io/travis/rjeczalik/refmt/master.svg)](https://travis-ci.org/rjeczalik/refmt "linux_amd64") [![Build status](https://img.shields.io/appveyor/ci/rjeczalik/refmt.svg)](https://ci.appveyor.com/project/rjeczalik/refmt "windows_amd64")
Reformat HCL ⇄ JSON and HCL ⇄ YAML.### install
```
$ go get github.com/rjeczalik/refmt
```### usage
```
usage:refmt [-t type] INPUT_FILE|"-" OUTPUT_FILE|"-"
Converts from one encoding to another. Supported formats (and their file extensions):
- HCL (.hcl or .tf)
- JSON (.json)
- YAML (.yaml or .yml)If INPUT_FILE's extension is not recognized or INPUT_FILE is "-" (stdin),
refmt will try to guess input format.If OUTPUT_FILE is "-" (stdout), destination format type is required to be
passed with -t flag.refmt [-t type] merge ORIGINAL_FILE|"-" MIXIN_FILE|"-" OUTPUT_FILE|"-"
Merges the object defined in ORIGINAL_FILE with the object from MIXIN_FILE, writing
the resulting object to the OUTPUT_FILE.The ORIGINAL_FILE, MIXIN_FILE and OUTPUT_FILE can have different encodings.
If ORIGINAL_FILE's extension is not recognized or ORIGINAL_FILE is "-" (stdin),
refmt will try to guess original format.If ORIGINAL_FILE does not exist or is empty, refmt is going to use empty
object instead.If MIXIN_FILE's extension is not recognized or MIXIN_FILE is "-" (stdin),
refmt will try to guess mixin format.If OUTPUT_FILE is "-" (stdout), destination format type is required to be
passed with -t flag.
```### docker usage
```
# build the refmt image
docker build -t refmt .# convert test.yml to hcl
cat test.yml | docker run -i --rm refmt -t hcl - -
```### examples
```
$ refmt -t yaml main.yaml -
```
```yaml
provider:
aws:
access_key: ${var.aws_access_key}
secret_key: ${var.aws_secret_key}
resource:
aws_instance:
aws-instance:
instance_type: t2.nano
user_data: echo "hello world!" >> /tmp/helloworld.txt
```
```
$ refmt main.yaml main.json
```
```json
{
"provider": {
"aws": {
"access_key": "${var.aws_access_key}",
"secret_key": "${var.aws_secret_key}"
}
},
"resource": {
"aws_instance": {
"aws-instance": {
"instance_type": "t2.nano",
"user_data": "echo \"hello world!\" >> /tmp/helloworld.txt"
}
}
}
}
```
```hcl
$ refmt main.json main.hcl
```
```
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
}resource "aws_instance" "aws-instance" {
instance_type = "t2.nano"
user_data = "echo \"hello world!\" >> /tmp/helloworld.txt"
}
```#### pretty reformat in-place
```
$ refmt main.tf.json main.tf.json
```### merge configurations
```yaml
$ cat ~/.kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority: /Volumes/rjk.io/.kube/ca.pem
server: https://178.0.20.1
name: default-cluster
contexts:
- context:
cluster: default-cluster
user: default-admin
name: default-system
current-context: default-system
kind: Config
preferences: {}
users:
- name: default-admin
user:
client-certificate: /Volumes/rjk.io/.kube/admin.pem
client-key: /Volumes/rjk.io/.kube/admin-key.pem
```
```yaml
$ cat >>another-cluster <