Skip to content

Commit

Permalink
Merge pull request #18821 from hashicorp/td-linter-for-data-source-reads
Browse files Browse the repository at this point in the history
linter: add rule to discourage data source referencing resource Read
  • Loading branch information
anGie44 authored Apr 15, 2021
2 parents 19f3351 + f924198 commit ca33f82
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion .semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ rules:
- pattern: '*aws.Time($VALUE)'
severity: WARNING

- id: data-source-with-resource-read
languages: [go]
message: Calling a resource's Read method from within a data-source is discouraged
paths:
include:
- aws/data_source_aws_*.go
patterns:
- pattern-regex: '(resource.+Read|flatten.+Resource)'
- pattern-inside: func $FUNCNAME(...) $RETURNTYPE { ... }
- pattern-not-inside: |
d.Set(..., []interface{}{ ... })
- pattern-not-inside: |
d.Set($ATTRIBUTE, $FUNC($APIOBJECT))
- metavariable-regex:
metavariable: "$FUNCNAME"
regex: "dataSource.+Read"
severity: WARNING

- id: helper-acctest-RandInt-compiled
languages: [go]
message: Using `acctest.RandInt()` in constant or variable declaration will execute during compilation and not randomize, pass into string generating function instead
Expand Down Expand Up @@ -211,7 +229,6 @@ rules:
expandStringList($LIST)
severity: WARNING


- id: helper-schema-ResourceData-GetOk-with-extraneous-conditional
languages: [go]
message: Zero value conditional check after `d.GetOk()` is extraneous
Expand Down

0 comments on commit ca33f82

Please sign in to comment.