Skip to content

Commit d640dce

Browse files
committed
Add terraform_map_duplicate_keys rule doc
1 parent b7a0528 commit d640dce

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All rules are enabled by default, but by setting `preset = "recommended"`, you c
1313
|[terraform_documented_outputs](terraform_documented_outputs.md)|Disallow `output` declarations without description||
1414
|[terraform_documented_variables](terraform_documented_variables.md)|Disallow `variable` declarations without description||
1515
|[terraform_empty_list_equality](terraform_empty_list_equality.md)|Disallow comparisons with `[]` when checking if a collection is empty||
16+
|[terraform_map_duplicate_keys](terraform_map_duplicate_keys.md)|Disallow duplicate keys in a map object||
1617
|[terraform_module_pinned_source](terraform_module_pinned_source.md)|Disallow specifying a git or mercurial repository as a module source without pinning to a version||
1718
|[terraform_module_version](terraform_module_version.md)|Checks that Terraform modules sourced from a registry specify a version||
1819
|[terraform_naming_convention](terraform_naming_convention.md)|Enforces naming conventions for resources, data sources, etc||
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# terraform_map_duplicate_keys
2+
3+
Disallow duplicate keys in a map object.
4+
5+
> This rule is enabled by "recommended" preset.
6+
7+
## Example
8+
9+
```hcl
10+
locals {
11+
map = {
12+
foo = 1
13+
bar = 2
14+
bar = 3 // duplicate key
15+
}
16+
}
17+
```
18+
19+
```
20+
$ tflint
21+
1 issue(s) found:
22+
23+
Warning: Duplicate key: "bar", first defined at main.tf:4,5-8 (terraform_map_duplicate_keys)
24+
25+
on main.tf line 5:
26+
5: bar = 3 // duplicated key
27+
28+
Reference: https://github.com/terraform-linters/tflint-ruleset-terraform/blob/v0.9.0/docs/rules/terraform_map_duplicate_keys.md
29+
```
30+
31+
## Why
32+
33+
In the Terraform language, duplicate map keys are overwritten rather than throwing an error. However, in most cases this behavior is not what you want and is often caused by a mistake. This rule will catch such mistakes early.
34+
35+
See also https://github.com/hashicorp/terraform/issues/28727
36+
37+
## How To Fix
38+
39+
Remove the duplicate keys and leave the correct value.

0 commit comments

Comments
 (0)