forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.semgrep.yml
817 lines (780 loc) · 27.2 KB
/
.semgrep.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
rules:
- id: acceptance-test-naming-parent-disappears
languages: [go]
message: Prefer naming acceptance tests with _disappears_Parent suffix
paths:
include:
- "internal/**/*_test.go"
patterns:
- pattern: func $FUNCNAME(t *testing.T) { ... }
- metavariable-regex:
metavariable: "$FUNCNAME"
regex: "^TestAcc[^_]+_([a-zA-Z]+[dD]isappears|[^_]+_disappears)$"
severity: WARNING
- id: aws-sdk-go-multiple-service-imports
languages: [go]
message: Resources should not implement multiple AWS service functionality
paths:
include:
- internal/
exclude:
- "internal/service/**/*_test.go"
- "internal/service/**/sweep.go"
- "internal/acctest/acctest.go"
- "internal/conns/**/*.go"
patterns:
- pattern: |
import ("$X")
import ("$Y")
- metavariable-regex:
metavariable: '$X'
regex: '^"github.com/aws/aws-sdk-go/service/[^/]+"$'
- metavariable-regex:
metavariable: '$Y'
regex: '^"github.com/aws/aws-sdk-go/service/[^/]+"$'
# wafregional uses a number of resources from waf
- pattern-not: |
import ("github.com/aws/aws-sdk-go/service/waf")
import ("github.com/aws/aws-sdk-go/service/wafregional")
severity: WARNING
- id: prefer-aws-go-sdk-pointer-conversion-assignment
languages: [go]
message: Prefer AWS Go SDK pointer conversion functions for dereferencing during assignment, e.g. aws.StringValue()
paths:
include:
- internal/service
exclude:
- "internal/service/**/*_test.go"
patterns:
- pattern: '$LHS = *$RHS'
- pattern-not: '*$LHS2 = *$RHS'
severity: WARNING
- id: prefer-aws-go-sdk-pointer-conversion-conditional
languages: [go]
message: Prefer AWS Go SDK pointer conversion functions for dereferencing during conditionals, e.g. aws.StringValue()
paths:
include:
- internal/service
exclude:
- "internal/service/**/*_test.go"
patterns:
- pattern-either:
- pattern: '$LHS == *$RHS'
- pattern: '$LHS != *$RHS'
- pattern: '$LHS > *$RHS'
- pattern: '$LHS < *$RHS'
- pattern: '$LHS >= *$RHS'
- pattern: '$LHS <= *$RHS'
- pattern: '*$LHS == $RHS'
- pattern: '*$LHS != $RHS'
- pattern: '*$LHS > $RHS'
- pattern: '*$LHS < $RHS'
- pattern: '*$LHS >= $RHS'
- pattern: '*$LHS <= $RHS'
severity: WARNING
- id: aws-go-sdk-pointer-conversion-ResourceData-SetId
fix: d.SetId(aws.StringValue($VALUE))
languages: [go]
message: Prefer AWS Go SDK pointer conversion aws.StringValue() function for dereferencing during d.SetId()
paths:
include:
- internal/
pattern: 'd.SetId(*$VALUE)'
severity: WARNING
- id: aws-go-sdk-pointer-conversion-immediate-dereference
fix: $VALUE
languages: [go]
message: Using AWS Go SDK pointer conversion, e.g. aws.String(), with immediate dereferencing is extraneous
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: '*aws.Bool($VALUE)'
- pattern: '*aws.Float64($VALUE)'
- pattern: '*aws.Int64($VALUE)'
- pattern: '*aws.String($VALUE)'
- 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:
- internal/service/**/*_data_source.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
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: const $CONST = fmt.Sprintf(..., <... acctest.RandInt() ...>, ...)
- pattern: var $VAR = fmt.Sprintf(..., <... acctest.RandInt() ...>, ...)
severity: WARNING
- id: helper-acctest-RandString-compiled
languages: [go]
message: Using `acctest.RandString()` in constant or variable declaration will execute during compilation and not randomize, pass into string generating function instead
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: const $CONST = fmt.Sprintf(..., <... acctest.RandString(...) ...>, ...)
- pattern: var $VAR = fmt.Sprintf(..., <... acctest.RandString(...) ...>, ...)
severity: WARNING
- id: helper-acctest-RandomWithPrefix-compiled
languages: [go]
message: Using `acctest.RandomWithPrefix()` in constant or variable declaration will execute during compilation and not randomize, pass into string generating function instead
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: const $CONST = fmt.Sprintf(..., <... acctest.RandomWithPrefix(...) ...>, ...)
- pattern: var $VAR = fmt.Sprintf(..., <... acctest.RandomWithPrefix(...) ...>, ...)
severity: WARNING
- id: helper-schema-Set-extraneous-NewSet-with-flattenStringList
languages: [go]
message: Prefer `flex.FlattenStringSet()` function for casting a list of string pointers to a set
paths:
include:
- internal/
pattern: schema.NewSet(schema.HashString, flex.FlattenStringList($APIOBJECT))
severity: WARNING
- id: helper-schema-Set-extraneous-expandStringList-with-List
languages: [go]
message: Prefer `flex.ExpandStringSet()` function for casting a set to a list of string pointers
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: flex.ExpandStringList($SET.List())
- pattern: |
$LIST := $SET.List()
...
flex.ExpandStringList($LIST)
severity: WARNING
- id: helper-schema-ResourceData-GetOk-with-extraneous-conditional
languages: [go]
message: Zero value conditional check after `d.GetOk()` is extraneous
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(bool) { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(int) != 0 { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(int) > 0 { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && $VALUE.(string) != "" { $BODY }
- pattern: if $VALUE, $OK := d.GetOk($KEY); $OK && len($VALUE.(string)) > 0 { $BODY }
severity: WARNING
- id: helper-schema-ResourceData-Set-extraneous-value-pointer-conversion
fix: d.Set($ATTRIBUTE, $APIOBJECT)
languages: [go]
message: AWS Go SDK pointer conversion function for `d.Set()` value is extraneous
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: d.Set($ATTRIBUTE, aws.BoolValue($APIOBJECT))
- pattern: d.Set($ATTRIBUTE, aws.Float64Value($APIOBJECT))
- pattern: d.Set($ATTRIBUTE, aws.IntValue($APIOBJECT))
- pattern: d.Set($ATTRIBUTE, aws.Int64Value($APIOBJECT))
- pattern: d.Set($ATTRIBUTE, int(aws.Int64Value($APIOBJECT)))
- pattern: d.Set($ATTRIBUTE, aws.StringValue($APIOBJECT))
severity: WARNING
# Not sure why this isn't working
# - id: helper-schema-ResourceData-DataSource-Set-tags
# languages: [go]
# message: (schema.ResourceData).Set() call with the tags key should include IgnoreConfig in the value
# paths:
# include:
# - internal/service/**/*_data_source.go
# exclude:
# - internal/service/**/*.go
# patterns:
# - pattern-inside: func $READMETHOD(...) $ERRORTYPE { ... }
# - pattern: if err := d.Set("tags", $TAGSMAP); err != nil { ... }
# - pattern-not: if err := d.Set("tags", $KEYVALUETAGS.IgnoreAws().IgnoreConfig($CONFIG).Map()); err != nil { ... }
# severity: WARNING
- id: helper-schema-ResourceData-Resource-Set-tags
languages: [go]
message: (schema.ResourceData).Set() call with the tags key should be preceded by a call to IgnoreConfig or include IgnoreConfig in the value in the case of ASG
paths:
include:
- internal/service/**/*.go
exclude:
- internal/service/**/*_data_source.go
patterns:
- pattern-inside: func $READMETHOD(...) $ERRORTYPE { ... }
- pattern-either:
- pattern: |
tags := $TAGS
...
if err := d.Set("tags", $TAGSMAP); err != nil { ... }
- pattern: |
tags = $TAGS
...
if err := d.Set("tags", $TAGSMAP); err != nil { ... }
- pattern: |
$ASGTAGS := keyvaluetags.AutoscalingKeyValueTags(...)
...
if err := d.Set("tags", $TAGSMAP); err != nil { ... }
- pattern-not-regex: 'keyvaluetags.AutoscalingKeyValueTags\(.+\).IgnoreAws\(\).IgnoreConfig'
- pattern-not: |
tags = $KEYVALUETAGS.IgnoreAws().IgnoreConfig($CONFIG)
...
- pattern-not: |
tags = $KEYVALUETAGS.$IGNORESERVICE().IgnoreConfig($CONFIG)
...
- pattern-not: |
tags := keyvaluetags.$VALUETAGS($RESOURCETAGS).IgnoreAws().IgnoreConfig($CONFIG)
...
- pattern-not: |
tags = keyvaluetags.$VALUETAGS($RESOURCETAGS).IgnoreAws().IgnoreConfig($CONFIG)
...
- pattern-not: |
tags = $VALUETAGS($RESOURCETAGS).IgnoreAWS().IgnoreConfig($CONFIG).Ignore($IGNORE)
...
severity: WARNING
- id: helper-schema-ResourceData-SetId-empty-without-IsNewResource-check
languages: [go]
message: Calling `d.SetId("")` should ensure `!d.IsNewResource()` is also checked. See https://github.com/hashicorp/terraform-provider-aws/blob/main/docs/contributing/error-handling.md#disnewresource-checks
paths:
include:
- internal/service
exclude:
- internal/service/**/*_data_source.go
- internal/service/backup
- internal/service/batch
- internal/service/d[a-d]*
- internal/service/devicefarm
- internal/service/directconnect
- internal/service/dlm
- internal/service/dms
- internal/service/ds
- internal/service/dynamodb
- internal/service/ec2
- internal/service/ecs
- internal/service/efs
- internal/service/elasticache
- internal/service/elasticbeanstalk
- internal/service/elastictranscoder
- internal/service/elbv2
- internal/service/emr
- internal/service/g*
- internal/service/inspector
- internal/service/iot
- internal/service/kafka
- internal/service/kms
- internal/service/lambda
- internal/service/lexmodels
- internal/service/licensemanager
- internal/service/lightsail
- internal/service/logs
- internal/service/macie
- internal/service/macie2
- internal/service/mediastore
- internal/service/mq
- internal/service/neptune
- internal/service/opsworks
- internal/service/organizations
- internal/service/pinpoint
- internal/service/rds
- internal/service/resourcegroups
- internal/service/route53
- internal/service/route53resolver
- internal/service/s[a-df-rt]*
- internal/service/se[d-z]*
- internal/service/sec[a-t]*
- internal/service/securityhub
- internal/service/ssoadmin
- internal/service/swf
- internal/service/[t-v]*
- internal/service/waf
- internal/service/wafv2
- internal/service/workspaces
- internal/service/xray
patterns:
- pattern-either:
- pattern: |
d.SetId("")
...
return nil
- pattern-not-inside: |
if ... {
if <... d.IsNewResource() ...> { ... }
...
d.SetId("")
...
return nil
}
- pattern-not-inside: |
if <... !d.IsNewResource() ...> { ... }
severity: WARNING
- id: helper-schema-resource-Retry-without-TimeoutError-check
languages: [go]
message: Check resource.Retry() errors with tfresource.TimedOut()
paths:
exclude:
- "*_test.go"
- sweep.go
include:
- internal/
patterns:
- pattern-either:
- patterns:
- pattern-either:
- pattern: |
$ERR := resource.Retry(...)
...
return ...
- pattern: |
$ERR = resource.Retry(...)
...
return ...
- pattern-not: |
$ERR := resource.Retry(...)
...
if isResourceTimeoutError($ERR) { ... }
...
return ...
- pattern-not: |
$ERR = resource.Retry(...)
...
if isResourceTimeoutError($ERR) { ... }
...
return ...
- pattern-not: |
$ERR := resource.Retry(...)
...
if tfresource.TimedOut($ERR) { ... }
...
return ...
- pattern-not: |
$ERR = resource.Retry(...)
...
if tfresource.TimedOut($ERR) { ... }
...
return ...
- patterns:
- pattern-either:
- pattern: |
$ERR := resource.RetryContext(...)
...
return ...
- pattern: |
$ERR = resource.RetryContext(...)
...
return ...
- pattern-not: |
$ERR := resource.RetryContext(...)
...
if isResourceTimeoutError($ERR) { ... }
...
return ...
- pattern-not: |
$ERR = resource.RetryContext(...)
...
if isResourceTimeoutError($ERR) { ... }
...
return ...
- pattern-not: |
$ERR := resource.RetryContext(...)
...
if tfresource.TimedOut($ERR) { ... }
...
return ...
- pattern-not: |
$ERR = resource.RetryContext(...)
...
if tfresource.TimedOut($ERR) { ... }
...
return ...
severity: WARNING
- id: helper-schema-TimeoutError-check-doesnt-return-output
languages: [go]
message: If the resource.Retry(), resource.RetryContext(), or tfresource.RetryConfigContext() function returns a value, ensure the isResourceTimeoutError() check does as well
paths:
exclude:
- "*_test.go"
include:
- internal/
patterns:
- pattern-either:
- patterns:
- pattern: |
if isResourceTimeoutError($ERR) {
_, $ERR = $CONN.$FUNC(...)
}
- pattern-not-inside: |
$ERR = resource.Retry(..., func() *resource.RetryError {
...
_, $ERR2 = $CONN.$FUNC(...)
...
})
...
if isResourceTimeoutError($ERR) { ... }
- pattern-not-inside: |
$ERR = resource.RetryContext(..., func() *resource.RetryError {
...
_, $ERR2 = $CONN.$FUNC(...)
...
})
...
if isResourceTimeoutError($ERR) { ... }
- pattern-not-inside: |
$ERR = tfresource.RetryConfigContext(..., func() *resource.RetryError {
...
_, $ERR2 = $CONN.$FUNC(...)
...
})
...
if tfresource.TimedOut($ERR) { ... }
- patterns:
- pattern: |
if tfresource.TimedOut($ERR) {
_, $ERR = $CONN.$FUNC(...)
}
- pattern-not-inside: |
$ERR = resource.Retry(..., func() *resource.RetryError {
...
_, $ERR2 = $CONN.$FUNC(...)
...
})
...
if tfresource.TimedOut($ERR) { ... }
- pattern-not-inside: |
$ERR = resource.RetryContext(..., func() *resource.RetryError {
...
_, $ERR2 = $CONN.$FUNC(...)
...
})
...
if tfresource.TimedOut($ERR) { ... }
- pattern-not-inside: |
$ERR = tfresource.RetryConfigContext(..., func() *resource.RetryError {
...
_, $ERR2 = $CONN.$FUNC(...)
...
})
...
if tfresource.TimedOut($ERR) { ... }
severity: WARNING
- id: is-not-found-error
languages: [go]
message: Check for resource.NotFoundError errors with tfresource.NotFound()
paths:
include:
- internal/
patterns:
- pattern-either:
- patterns:
- pattern: |
var $CAST *resource.NotFoundError
...
errors.As($ERR, &$CAST)
- pattern-not-inside: |
var $CAST *resource.NotFoundError
...
errors.As($ERR, &$CAST)
...
$CAST.$FIELD
- patterns:
- pattern: |
$X, $Y := $ERR.(*resource.NotFoundError)
severity: WARNING
- id: time-equality
languages: [go]
message: Use time.Equal() instead of ==
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: |
aws.TimeValue($X) == $Y
- pattern: |
aws.TimeValue($X) != $Y
- pattern: |
($X : time.Time) == $Y
- pattern: |
($X : time.Time) != $Y
- pattern: |
$X == aws.TimeValue($Y)
- pattern: |
$X != aws.TimeValue($Y)
- pattern: |
$X == ($Y : time.Time)
- pattern: |
$X != ($Y : time.Time)
severity: WARNING
- id: prefer-pagination-bool-var-last-page
languages: [go]
message: Use lastPage for bool variable in pagination functions
paths:
include:
- internal/
patterns:
- pattern: |
$X.$Z(..., func(..., $Y bool) {
...
})
- pattern-not: |
$X.$Z(..., func(..., lastPage bool) {
...
})
- pattern-not: |
$X.$Z(..., func(..., _ bool) {
...
})
- metavariable-regex:
metavariable: '$Z'
regex: '.*Pages$'
severity: WARNING
- id: calling-fmt.Print-and-variants
languages: [go]
message: Do not call `fmt.Print` and variant
paths:
include:
- internal/
exclude:
- providerlint/vendor/
- internal/generate/
patterns:
- pattern-either:
- pattern: |
fmt.Print(...)
- pattern: |
fmt.Printf(...)
- pattern: |
fmt.Println(...)
severity: WARNING
- id: domain-names
languages: [go]
message: Domain names should be in the namespaces defined in RFC 6761 (https://datatracker.ietf.org/doc/html/rfc6761) as reserved for testing
paths:
include:
- internal/service
exclude:
- internal/service/firehose/delivery_stream_test.go
- internal/service/fsx/windows_file_system_test.go
- internal/service/iam/openid_connect_provider_test.go
- internal/service/mq/broker_test.go
- internal/service/mq/forge_test.go
- internal/service/route53/sweep.go
- internal/service/s3/bucket_test.go
- internal/service/s3/object_test.go
- internal/service/storagegateway/cached_iscsi_volume.go
- internal/service/storagegateway/cached_iscsi_volume_test.go
- internal/service/storagegateway/stored_iscsi_volume_test.go
- internal/service/transfer/access_test.go
- internal/service/transfer/server_test.go
- "internal/service/**/*_test.go"
patterns:
- patterns:
- pattern-regex: '(([-a-zA-Z0-9]{2,}\.)|(%[sdftq]))+(com|net|org)\b'
- pattern-inside: '($X : string)'
- pattern-not-regex: 'amazonaws\.com'
- pattern-not-regex: 'awsapps\.com'
- pattern-not-regex: '@(([-a-zA-Z0-9]{2,}\.)|(%[sdftq]))+(com|net|org)\b' # exclude domain names in email addresses
- pattern-not-regex: '[^-a-zA-Z0-9]example\.com'
- pattern-not-regex: '[^-a-zA-Z0-9]example\.net'
- pattern-not-regex: '[^-a-zA-Z0-9]example\.org'
- pattern-not-regex: 'github\.com'
- pattern-not-regex: 'aws\.amazon\.com'
- pattern-not-regex: 'graph\.facebook\.com'
- pattern-not-regex: 'people\.googleapis\.com'
- pattern-not-regex: 'www\.googleapis\.com'
- pattern-not-regex: 'accounts\.google\.com'
- pattern-not-regex: '[-a-z0-9]+\.apps\.googleusercontent\.com'
- pattern-not-regex: 'elasticbeanstalk\.com'
- pattern-not-regex: 'awsglobalaccelerator\.com'
- pattern-not-regex: 'cloudfront\.net'
- pattern-not-regex: 'http://json-schema\.org/draft-0\d/schema'
- pattern-not-regex: 'http://activemq.apache.org/schema/core'
- pattern-not-regex: 'mcr.microsoft.com'
severity: WARNING
- id: email-address
languages: [go]
message: Use default email address or generate a random email address. https://github.com/hashicorp/terraform-provider-aws/blob/main/docs/contributing/running-and-writing-acceptance-tests.md#hardcoded-email-addresses
paths:
include:
- internal/
exclude:
- internal/service/route53domains/registered_domain_test.go
patterns:
- pattern-regex: '[-_A-Za-z0-9.+]+@([-A-Za-z0-9]+\.)(com|net|org)'
- pattern-not-regex: 'no-reply@hashicorp\.com'
- pattern-inside: '($X : string)'
severity: WARNING
- id: ssh-key
languages: [go]
message: Generate random SSH keys using acctest.RandSSHKeyPair() or RandSSHKeyPairSize(). https://github.com/hashicorp/terraform-provider-aws/blob/main/docs/contributing/running-and-writing-acceptance-tests.md#hardcoded-ssh-key
paths:
include:
- internal/
exclude:
- providerlint/vendor/
patterns:
# This isn't technically the correct regex, but for some reason adding a '+' causes the regex to
# miss some SSH keys. AFAICT, this is good enough.
- pattern-regex: 'ssh-rsa [A-Za-z0-9/]+'
- pattern-inside: '($X : string)'
severity: WARNING
- id: non-tags-change-detection
languages: [go]
message: Incorrect form of non-tags change detection. https://github.com/hashicorp/terraform-provider-aws/blob/main/docs/contributing/contribution-checklists.md#resource-tagging-code-implementation
paths:
include:
- internal/
patterns:
- pattern: 'if d.HasChangeExcept("tags_all") {...}'
severity: WARNING
- id: unnecessary-literal-type-conversion
languages: [go]
message: Literal numbers do not need type conversions
paths:
include:
- internal/
patterns:
- pattern: "aws.Int64(int64($X))"
- metavariable-regex:
metavariable: $X
regex: (\d+)
severity: ERROR
fix: "aws.Int64($X)"
- id: calling-SetId-with-empty-string-in-resource-create
languages: [go]
message: Do not call `d.SetId("")` inside a resource create function
paths:
include:
- internal/service/
patterns:
- pattern: |
func $FUNC(...) {
...
d.SetId("")
}
- metavariable-regex:
metavariable: "$FUNC"
regex: "^resource\\w*(Create|Put|Set|Upsert|Enable)$"
severity: WARNING
- id: calling-SetId-with-empty-string-in-resource-update
languages: [go]
message: Do not call `d.SetId("")` inside a resource update function
paths:
include:
- internal/service/
patterns:
- pattern: |
func $FUNC(...) {
...
d.SetId("")
}
- metavariable-regex:
metavariable: "$FUNC"
regex: "^resource\\w*(Update)$|^update\\w*$" # Put and Upsert variants are handled in calling-SetId-with-empty-string-in-resource-create above
severity: WARNING
- id: calling-SetId-in-resource-delete
languages: [go]
message: Do not call `d.SetId(...)` inside a resource delete function
paths:
include:
- internal/service/
patterns:
- pattern: |
func $FUNC(...) {
...
d.SetId(...)
}
- metavariable-regex:
metavariable: "$FUNC"
regex: "^resource\\w*(Delete|Disable)$"
severity: WARNING
- id: avoid-string-is-empty-validation
languages: [go]
message: Empty strings should not be included in validation
paths:
include:
- internal/
patterns:
- pattern: validation.Any(..., validation.StringIsEmpty, ...)
severity: ERROR
- id: use-error-code-equals-if-not-checking-message
languages: [go]
message: Use tfawserr.ErrCodeEquals() when message parameter is empty string
paths:
include:
- internal/
patterns:
- pattern: tfawserr.ErrMessageContains(err, ..., "")
severity: ERROR
- id: avoid-dependency-for-one-constant
languages: [go]
message: Use constant in the same package rather than importing iam for a constant
paths:
include:
- internal/
exclude:
- internal/service/iam
patterns:
- pattern: tfiam.PropagationTimeout
severity: ERROR
- id: use-acctest-provider-factories
languages: [go]
message: Use acctest.ProviderFactories, not acctest.Providers
paths:
include:
- "internal/**/*_test.go"
pattern-regex: Providers:\s+(acctest\.)?Providers,
severity: WARNING
- id: prefer-aws-go-sdk-pointer-conversion-int-conversion-int64-pointer
fix: $VALUE
languages: [go]
message: Prefer AWS Go SDK pointer conversion functions for dereferencing when converting int64 to int
paths:
include:
- internal/
pattern: int(*$VALUE)
severity: WARNING
- id: aws-go-sdk-error-code-helper
languages: [go]
message: 'Use `tfawserr` helpers for checking AWS Go SDK errors (e.g. `tfawserr.ErrMessageContains(err, CODE, MESSAGE)`)'
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: if $AWSERR, $OK := $ORIGINALERR.(awserr.Error); $OK && $AWSERR.Code() == $CODE { $BODY }
- pattern: |
if $AWSERR, $OK := $ORIGINALERR.(awserr.Error); $OK {
if $AWSERR.Code() == $CODE { $BODY }
}
severity: WARNING
- id: fmt-Errorf-awserr-Error-Code
languages: [go]
message: Prefer `err` with `%w` format verb instead of `err.Code()` or `err.Message()`
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: fmt.Errorf(..., $ERR.Code(), ...)
- pattern: fmt.Errorf(..., $ERR.Message(), ...)
severity: WARNING