You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add JSON configuration file support with centralized plugin version checking
- Add support for JSON configuration files (.tflint.json)
- Detect JSON configs by file extension, not filename pattern
- Centralize all plugin version checking logic into plugin/plugin_version.go
- Enforce SDK version 0.23+ for JSON configuration support
- Split version checking: TFLint constraints checked before ApplyGlobalConfig,
SDK versions checked after to avoid plugin initialization failures
- Add comprehensive unit tests for SDK version validation
- Update documentation to mention JSON configuration support
This allows users to use JSON configuration files with any name when
using the --config flag, while ensuring proper plugin compatibility.
// VersionConstraints endpoint is available in tflint-plugin-sdk v0.14+.
274
-
returnrulesetPlugin, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
275
-
} else {
276
-
returnrulesetPlugin, fmt.Errorf(`Failed to get TFLint version constraints to "%s" plugin; %w`, name, err)
260
+
// Plugin is too old
261
+
returnrulesetPlugin, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.DefaultSDKVersionConstraints)
277
262
}
263
+
returnrulesetPlugin, fmt.Errorf(`Failed to get TFLint version constraints to "%s" plugin; %w`, name, err)
278
264
}
279
-
if!constraints.Check(tflint.Version) {
280
-
returnrulesetPlugin, fmt.Errorf("Failed to satisfy version constraints; tflint-ruleset-%s requires %s, but TFLint version is %s", name, constraints, tflint.Version)
Copy file name to clipboardExpand all lines: docs/user-guide/config.md
+42-3Lines changed: 42 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,12 @@ You can change the behavior not only in CLI flags but also in config files. TFLi
4
4
5
5
1. File passed by the `--config` option
6
6
2. File set by the `TFLINT_CONFIG_FILE` environment variable
7
-
3. Current directory (`./.tflint.hcl`)
8
-
4. Home directory (`~/.tflint.hcl`)
7
+
3. Current directory `./.tflint.hcl`
8
+
4. Current directory `./.tflint.json`
9
+
5. Home directory `~/.tflint.hcl`
10
+
6. Home directory `~/.tflint.json`
9
11
10
-
The config file is written in [HCL](https://github.com/hashicorp/hcl). An example is shown below:
12
+
The config file can be written in either [HCL](https://github.com/hashicorp/hcl) or JSON format, determined by the file extension. JSON files use the [HCL-compatible JSON syntax](https://developer.hashicorp.com/terraform/language/syntax/json), following the same structure as Terraform's `.tf.json` files. An HCL example is shown below:
The file path is resolved relative to the module directory when `--chdir` or `--recursive` is used. To use a config file from the working directory when recursing, pass an absolute path:
// VersionConstraints endpoint is available in tflint-plugin-sdk v0.14+.
53
-
returnnil, nil, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
51
+
returnnil, nil, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.DefaultSDKVersionConstraints)
54
52
} else {
55
53
returnnil, nil, fmt.Errorf(`Failed to get TFLint version constraints to "%s" plugin; %w`, name, err)
56
54
}
57
55
}
58
-
if!constraints.Check(tflint.Version) {
59
-
returnnil, nil, fmt.Errorf("Failed to satisfy version constraints; tflint-ruleset-%s requires %s, but TFLint version is %s", name, constraints, tflint.Version)
returnfmt.Errorf("Failed to satisfy version constraints; tflint-ruleset-%s requires %s, but TFLint version is %s", pluginName, constraints, tflint.Version)
28
+
}
29
+
returnnil
30
+
}
31
+
32
+
// CheckSDKVersionSatisfiesConstraints validates if a plugin's SDK version meets the minimum requirements.
33
+
// For HCL configs, requires SDK >= 0.16.0. For JSON configs, requires SDK >= 0.23.0.
0 commit comments