@@ -24,6 +24,7 @@ import (
24
24
"github.com/hashicorp/terraform-provider-aws/internal/flex"
25
25
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
26
26
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
27
+ "github.com/hashicorp/terraform-provider-aws/internal/verify"
27
28
"github.com/hashicorp/terraform-provider-aws/names"
28
29
)
29
30
@@ -71,11 +72,69 @@ func resourceAnalyzer() *schema.Resource {
71
72
MaxItems : 1 ,
72
73
Elem : & schema.Resource {
73
74
Schema : map [string ]* schema.Schema {
75
+ "internal_access" : {
76
+ Type : schema .TypeList ,
77
+ Optional : true ,
78
+ ForceNew : true ,
79
+ MaxItems : 1 ,
80
+ ConflictsWith : []string {"configuration.0.unused_access" },
81
+ Elem : & schema.Resource {
82
+ Schema : map [string ]* schema.Schema {
83
+ "analysis_rule" : {
84
+ Type : schema .TypeList ,
85
+ Optional : true ,
86
+ ForceNew : true ,
87
+ MaxItems : 1 ,
88
+ Elem : & schema.Resource {
89
+ Schema : map [string ]* schema.Schema {
90
+ "inclusion" : {
91
+ Type : schema .TypeList ,
92
+ Optional : true ,
93
+ ForceNew : true ,
94
+ Elem : & schema.Resource {
95
+ Schema : map [string ]* schema.Schema {
96
+ "account_ids" : {
97
+ Type : schema .TypeList ,
98
+ Optional : true ,
99
+ ForceNew : true ,
100
+ Elem : & schema.Schema {
101
+ Type : schema .TypeString ,
102
+ ValidateFunc : verify .ValidAccountID ,
103
+ },
104
+ },
105
+ "resource_arns" : {
106
+ Type : schema .TypeList ,
107
+ Optional : true ,
108
+ ForceNew : true ,
109
+ Elem : & schema.Schema {
110
+ Type : schema .TypeString ,
111
+ ValidateFunc : verify .ValidARN ,
112
+ },
113
+ },
114
+ "resource_types" : {
115
+ Type : schema .TypeList ,
116
+ Optional : true ,
117
+ ForceNew : true ,
118
+ Elem : & schema.Schema {
119
+ Type : schema .TypeString ,
120
+ ValidateDiagFunc : enum .Validate [types.ResourceType ](),
121
+ },
122
+ },
123
+ },
124
+ },
125
+ },
126
+ },
127
+ },
128
+ },
129
+ },
130
+ },
131
+ },
74
132
"unused_access" : {
75
- Type : schema .TypeList ,
76
- Optional : true ,
77
- ForceNew : true ,
78
- MaxItems : 1 ,
133
+ Type : schema .TypeList ,
134
+ Optional : true ,
135
+ ForceNew : true ,
136
+ MaxItems : 1 ,
137
+ ConflictsWith : []string {"configuration.0.internal_access" },
79
138
Elem : & schema.Resource {
80
139
Schema : map [string ]* schema.Schema {
81
140
"analysis_rule" : {
@@ -98,7 +157,7 @@ func resourceAnalyzer() *schema.Resource {
98
157
MaxItems : 2000 ,
99
158
Elem : & schema.Schema {
100
159
Type : schema .TypeString ,
101
- ValidateFunc : validation . StringMatch ( regexache . MustCompile ( `^\d{12}$` ), "Must be a 12-digit account ID" ) ,
160
+ ValidateFunc : verify . ValidAccountID ,
102
161
},
103
162
},
104
163
names .AttrResourceTags : {
@@ -268,10 +327,94 @@ func expandAnalyzerConfiguration(tfMap map[string]any) types.AnalyzerConfigurati
268
327
return nil
269
328
}
270
329
271
- apiObject := & types.AnalyzerConfigurationMemberUnusedAccess {}
330
+ var apiObject types.AnalyzerConfiguration
272
331
332
+ if v , ok := tfMap ["internal_access" ].([]any ); ok && len (v ) > 0 && v [0 ] != nil {
333
+ internalAccess := & types.AnalyzerConfigurationMemberInternalAccess {}
334
+ internalAccess .Value = expandInternalAccessConfiguration (v [0 ].(map [string ]any ))
335
+ apiObject = internalAccess
336
+ }
273
337
if v , ok := tfMap ["unused_access" ].([]any ); ok && len (v ) > 0 && v [0 ] != nil {
274
- apiObject .Value = expandUnusedAccessConfiguration (v [0 ].(map [string ]any ))
338
+ unusedAccess := & types.AnalyzerConfigurationMemberUnusedAccess {}
339
+ unusedAccess .Value = expandUnusedAccessConfiguration (v [0 ].(map [string ]any ))
340
+ apiObject = unusedAccess
341
+ }
342
+
343
+ return apiObject
344
+ }
345
+
346
+ func expandInternalAccessConfiguration (tfMap map [string ]any ) types.InternalAccessConfiguration {
347
+ apiObject := types.InternalAccessConfiguration {}
348
+
349
+ if v , ok := tfMap ["analysis_rule" ].([]any ); ok && len (v ) > 0 && v [0 ] != nil {
350
+ apiObject .AnalysisRule = expandInternalAccessAnalysisRule (v [0 ].(map [string ]any ))
351
+ }
352
+
353
+ return apiObject
354
+ }
355
+
356
+ func expandInternalAccessAnalysisRule (tfMap map [string ]any ) * types.InternalAccessAnalysisRule {
357
+ apiObject := & types.InternalAccessAnalysisRule {}
358
+
359
+ if v , ok := tfMap ["inclusion" ].([]any ); ok && len (v ) > 0 {
360
+ apiObject .Inclusions = expandInternalAccessAnalysisRuleCriterias (v )
361
+ }
362
+
363
+ return apiObject
364
+ }
365
+
366
+ func expandInternalAccessAnalysisRuleCriterias (tfList []any ) []types.InternalAccessAnalysisRuleCriteria {
367
+ if len (tfList ) == 0 {
368
+ return nil
369
+ }
370
+
371
+ var apiObjects []types.InternalAccessAnalysisRuleCriteria
372
+
373
+ for _ , tfMapRaw := range tfList {
374
+ tfMap , ok := tfMapRaw .(map [string ]any )
375
+ if ! ok {
376
+ continue
377
+ }
378
+
379
+ apiObject := expandInternalAccessAnalysisRuleCriteria (tfMap )
380
+
381
+ if apiObject == nil {
382
+ continue
383
+ }
384
+
385
+ apiObjects = append (apiObjects , * apiObject )
386
+ }
387
+
388
+ return apiObjects
389
+ }
390
+
391
+ func expandInternalAccessAnalysisRuleCriteria (tfMap map [string ]any ) * types.InternalAccessAnalysisRuleCriteria {
392
+ if tfMap == nil {
393
+ return nil
394
+ }
395
+
396
+ apiObject := & types.InternalAccessAnalysisRuleCriteria {}
397
+
398
+ if tfList , ok := tfMap ["account_ids" ].([]any ); ok && len (tfList ) > 0 {
399
+ for _ , v := range tfList {
400
+ accountID , ok := v .(string )
401
+ if ! ok {
402
+ continue
403
+ }
404
+ apiObject .AccountIds = append (apiObject .AccountIds , accountID )
405
+ }
406
+ }
407
+
408
+ if tfList , ok := tfMap ["resource_arns" ].([]any ); ok && len (tfList ) > 0 {
409
+ for _ , v := range tfList {
410
+ apiObject .ResourceArns = append (apiObject .ResourceArns , v .(string ))
411
+ }
412
+ }
413
+
414
+ if tfList , ok := tfMap ["resource_types" ].([]any ); ok && len (tfList ) > 0 {
415
+ for _ , v := range tfList {
416
+ apiObject .ResourceTypes = append (apiObject .ResourceTypes , types .ResourceType (v .(string )))
417
+ }
275
418
}
276
419
277
420
return apiObject
@@ -360,13 +503,82 @@ func flattenAnalyzerConfiguration(apiObject types.AnalyzerConfiguration) map[str
360
503
tfMap := map [string ]any {}
361
504
362
505
switch v := apiObject .(type ) {
506
+ case * types.AnalyzerConfigurationMemberInternalAccess :
507
+ tfMap ["internal_access" ] = []any {flattenInternalAccessConfiguration (& v .Value )}
363
508
case * types.AnalyzerConfigurationMemberUnusedAccess :
364
509
tfMap ["unused_access" ] = []any {flattenUnusedAccessConfiguration (& v .Value )}
365
510
}
366
511
367
512
return tfMap
368
513
}
369
514
515
+ func flattenInternalAccessConfiguration (apiObject * types.InternalAccessConfiguration ) map [string ]any {
516
+ if apiObject == nil {
517
+ return nil
518
+ }
519
+
520
+ tfMap := map [string ]any {}
521
+
522
+ if v := apiObject .AnalysisRule ; v != nil {
523
+ tfMap ["analysis_rule" ] = []any {flattenInternalAccessAnalysisRule (v )}
524
+ }
525
+
526
+ return tfMap
527
+ }
528
+
529
+ func flattenInternalAccessAnalysisRule (apiObject * types.InternalAccessAnalysisRule ) map [string ]any {
530
+ if apiObject == nil {
531
+ return nil
532
+ }
533
+
534
+ tfMap := map [string ]any {}
535
+
536
+ if v := apiObject .Inclusions ; v != nil {
537
+ tfMap ["inclusion" ] = flattenInternalAccessAnalysisRuleCriterias (v )
538
+ }
539
+
540
+ return tfMap
541
+ }
542
+
543
+ func flattenInternalAccessAnalysisRuleCriterias (apiObjects []types.InternalAccessAnalysisRuleCriteria ) []any {
544
+ if len (apiObjects ) == 0 {
545
+ return nil
546
+ }
547
+
548
+ var tfList []any
549
+
550
+ for _ , apiObject := range apiObjects {
551
+ tfMap := flattenInternalAccessAnalysisRuleCriteria (& apiObject )
552
+ if tfMap != nil {
553
+ tfList = append (tfList , tfMap )
554
+ }
555
+ }
556
+
557
+ return tfList
558
+ }
559
+
560
+ func flattenInternalAccessAnalysisRuleCriteria (apiObject * types.InternalAccessAnalysisRuleCriteria ) map [string ]any {
561
+ if apiObject == nil {
562
+ return nil
563
+ }
564
+
565
+ tfMap := map [string ]any {}
566
+
567
+ if v := apiObject .AccountIds ; len (v ) > 0 {
568
+ tfMap ["account_ids" ] = v
569
+ }
570
+
571
+ if v := apiObject .ResourceArns ; len (v ) > 0 {
572
+ tfMap ["resource_arns" ] = v
573
+ }
574
+
575
+ if v := apiObject .ResourceTypes ; len (v ) > 0 {
576
+ tfMap ["resource_types" ] = v
577
+ }
578
+
579
+ return tfMap
580
+ }
581
+
370
582
func flattenUnusedAccessConfiguration (apiObject * types.UnusedAccessConfiguration ) map [string ]any {
371
583
if apiObject == nil {
372
584
return nil
0 commit comments