Parses and compares Terraform HCL IaC files.
npm i @fredlackey/hcl-parser
Each file converted to a object structured as follows:
{
name : 'filename.tf',
path : '/var/hcl/all-files/filename.tf',
nodes: [] // Array of Nodes found within the file
}
{
lines : [], // Lines from the HCL file for the node
name : 'aws_instance(my-instance)',
props : {},
tags : {},
tagsAll: {}
}
The HCL Parser will load and compare single Terraform HCL IaC files or a full directory structure of files. Supply either a folder path or a file path.
const hclParser = require('@fredlackey/hcl-parser');
const TEST_FOLDER = '/var/hcl/all-files';
const main = async () => {
const data = await parse(TEST_FOLDER);
console.log(data);
};
main();
Resulting data:
{
files: [], // Array of files with nodes
request: '' // Supplied file or folder path
}
const hclParser = require('fredlackey/hcl-parser');
const CURRENT = '/var/hcl/current-files';
const PREVIOUS = '/var/hcl/previous-files';
const main = async () => {
const data = await parse(CURRENT, PREVIOUS);
console.log(data);
};
main();
Resulting data:
{
comparison: {
changed: [], // List of nodes with differences
missing: [], // List of missing nodes
new: [] // List of new nodes
},
current: {
files: [], // Array of files with nodes
request: '' // Supplied file or folder path
},
previous: {
files: [], // Array of files with nodes
request: '' // Supplied file or folder path
},
}
Detection of Tags / Tags All only works with AWS at the moment. Will be expanding to support Google Cloud Platform's Label logic.
Need a hand with your Terraform implementation? Feel free to drop me a note:
Fred Lackey
https://fredlackey.com
fred.lackey@gmail.com