Add new rule: terraform_map_duplicate_values
#224
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new rule
terraform_map_duplicate_values
to the TFLint ruleset that disallows duplicate values in a map object.The use-case is the following: I use maps for storing configuration data (e.g., SSM parameters), and I would like to make sure no duplicated values are added there.
# tflint-ignore: terraform_map_duplicate_values
still works fineMaybe it's a too niche case, happy to hear your thoughts and address any questions you might have!
New Rule Implementation:
rules/terraform_map_duplicate_values.go
: Added theTerraformMapDuplicateValuesRule
to check for duplicate values in map objects. This rule evaluates expressions to identify and report any duplicate values. Basically, mimics the similar rule that was already here for map keys.Rule Registration:
rules/preset.go
: Registered the newTerraformMapDuplicateValuesRule
in the preset rules map.Documentation:
docs/rules/terraform_map_duplicate_values.md
: Added documentation for the new rule, including examples, rationale, and instructions on how to fix issues detected by the rule.Tests:
rules/terraform_map_duplicate_values_test.go
: Added tests for the new rule, covering various scenarios such as maps with no duplicates, maps with duplicate values, and handling of different data types.