Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anubhavmishra/json2hcl
Convert JSON to HCL
https://github.com/anubhavmishra/json2hcl
hcl json packer
Last synced: 23 days ago
JSON representation
Convert JSON to HCL
- Host: GitHub
- URL: https://github.com/anubhavmishra/json2hcl
- Owner: anubhavmishra
- License: mit
- Created: 2019-12-17T05:53:00.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-17T05:56:53.000Z (about 5 years ago)
- Last Synced: 2024-10-28T13:47:23.518Z (2 months ago)
- Topics: hcl, json, packer
- Language: Go
- Size: 7.81 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json2hcl
Convert JSON to HCL
## Usage
Download the latest version of `json2hcl` from [releases](https://github.com/anubhavmishra/json2hcl/releases).
### Packer JSON config file to HCL example
Packer JSON config file [examples/packer-config.json](./examples/packer-config.json)
```json
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-example {{timestamp}}"
}]
}
```Convert Packer JSON config file to HCL
```bash
json2hcl < examples/packer-config.json
"variables" = {
"aws_access_key" = """aws_secret_key" = ""
}"builders" = {
"type" = "amazon-ebs""access_key" = "{{user `aws_access_key`}}"
"secret_key" = "{{user `aws_secret_key`}}"
"region" = "us-east-1"
"source_ami_filter" = {
"filters" = {
"virtualization-type" = "hvm""name" = "ubuntu/images/*ubuntu-xenial-16.04-amd64-server-*"
"root-device-type" = "ebs"
}"owners" = ["099720109477"]
"most_recent" = true
}"instance_type" = "t2.micro"
"ssh_username" = "ubuntu"
"ami_name" = "packer-example {{timestamp}}"
}
```To validate Packer HCL configuration run the following command
```bash
packer validate packer-config.hcl
Template validated successfully.
```## Acknowledgements
This project is inspired by [kvz/json2hcl](https://github.com/kvz/json2hcl). This project aims to be
lightweight and only support JSON to HCL conversion. If you want to convert HCL to JSON, please use
[kvz/json2hcl](https://github.com/kvz/json2hcl).