-
Notifications
You must be signed in to change notification settings - Fork 380
Description
Introduction
TFLint currently appears to only accepts configuration files in HCL format (.tflint.hcl). This limitation makes it challenging to programmatically generate TFLint configurations from build systems and tools that natively work with JSON. Supporting JSON format for TFLint configuration files would enable better integration with automated tooling and build systems.
Proposal
Add support for JSON-formatted configuration files in TFLint, similar to how Terraform itself supports both .tf (HCL) and .tf.json (JSON) formats. This would allow TFLint to accept configuration files named .tflint.json in addition to the existing .tflint.hcl.
For what it's worth, this should likely be simply a case of exposing the json parser of the hcl/v2 library using hclparse.ParseJSON()
. If you're happy to proceed, I will make a PR, with tests, to introduce it to the parser.
Use cases:
- Build systems like Bazel that have strong JSON support can programmatically generate TFLint configurations
- CI/CD pipelines can dynamically create configurations using JSON templating tools
- Teams using infrastructure-as-code generators can emit TFLint config alongside Terraform JSON
- Integration with tools that already output JSON-based configurations (e.g., policy engines, compliance tools)
Example .tflint.json:
{
"config": {
"format": "compact",
"module": true
},
"plugin": {
"aws": {
"enabled": true,
"version": "0.21.0",
"source": "github.com/terraform-linters/tflint-ruleset-aws"
}
},
"rule": {
"terraform_naming_convention": {
"enabled": true
}
}
}
Implementation Approach
- Accept both
.tflint.hcl
and.tflint.json
as valid configuration filenames - When
.tflint.json
is detected, parse it as JSON and convert to the internal configuration structure - Maintain backward compatibility by continuing to support HCL format
- Follow the same JSON structure conventions that Terraform uses for .tf.json files
References
- Terraform JSON Configuration Syntax: https://www.terraform.io/docs/language/syntax/json.html
- Bazel's native JSON support via json.encode(): https://bazel.build/rules/lib/json
- Similar feature in Terraform allowing both HCL and JSON formats