@@ -11,7 +11,9 @@ import (
11
11
"github.com/crowdstrike/gofalcon/falcon/client/filevantage"
12
12
"github.com/crowdstrike/gofalcon/falcon/models"
13
13
"github.com/crowdstrike/terraform-provider-crowdstrike/internal/scopes"
14
+ "github.com/crowdstrike/terraform-provider-crowdstrike/internal/utils"
14
15
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
16
+ "github.com/hashicorp/terraform-plugin-framework/attr"
15
17
"github.com/hashicorp/terraform-plugin-framework/diag"
16
18
"github.com/hashicorp/terraform-plugin-framework/path"
17
19
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -56,7 +58,7 @@ type filevantageRuleGroupResourceModel struct {
56
58
Name types.String `tfsdk:"name"`
57
59
Type types.String `tfsdk:"type"`
58
60
Description types.String `tfsdk:"description"`
59
- Rules [] * fimRule `tfsdk:"rules"`
61
+ Rules types. List `tfsdk:"rules"`
60
62
LastUpdated types.String `tfsdk:"last_updated"`
61
63
}
62
64
@@ -102,6 +104,47 @@ type fimRule struct {
102
104
WatchDeleteValueChanges types.Bool `tfsdk:"watch_key_value_delete_changes"`
103
105
}
104
106
107
+ func (f fimRule ) attrTypes () map [string ]attr.Type {
108
+ return map [string ]attr.Type {
109
+ "id" : types .StringType ,
110
+ "description" : types .StringType ,
111
+ "precedence" : types .Int64Type ,
112
+ "path" : types .StringType ,
113
+ "severity" : types .StringType ,
114
+ "depth" : types .StringType ,
115
+ "include" : types .StringType ,
116
+ "exclude" : types .StringType ,
117
+ "include_users" : types .StringType ,
118
+ "include_processes" : types .StringType ,
119
+ "exclude_users" : types .StringType ,
120
+ "exclude_processes" : types .StringType ,
121
+ "file_names" : types.ListType {
122
+ ElemType : types .StringType ,
123
+ },
124
+ "registry_values" : types.ListType {
125
+ ElemType : types .StringType ,
126
+ },
127
+ "enable_content_capture" : types .BoolType ,
128
+ "watch_directory_delete_changes" : types .BoolType ,
129
+ "watch_directory_create_changes" : types .BoolType ,
130
+ "watch_directory_rename_changes" : types .BoolType ,
131
+ "watch_directory_attribute_changes" : types .BoolType ,
132
+ "watch_directory_permission_changes" : types .BoolType ,
133
+ "watch_file_rename_changes" : types .BoolType ,
134
+ "watch_file_write_changes" : types .BoolType ,
135
+ "watch_file_create_changes" : types .BoolType ,
136
+ "watch_file_delete_changes" : types .BoolType ,
137
+ "watch_file_attribute_changes" : types .BoolType ,
138
+ "watch_file_permission_changes" : types .BoolType ,
139
+ "watch_key_create_changes" : types .BoolType ,
140
+ "watch_key_delete_changes" : types .BoolType ,
141
+ "watch_key_rename_changes" : types .BoolType ,
142
+ "watch_key_permissions_changes" : types .BoolType ,
143
+ "watch_key_value_set_changes" : types .BoolType ,
144
+ "watch_key_value_delete_changes" : types .BoolType ,
145
+ }
146
+ }
147
+
105
148
// Configure adds the provider configured client to the resource.
106
149
func (r * filevantageRuleGroupResource ) Configure (
107
150
ctx context.Context ,
@@ -493,8 +536,13 @@ func (r *filevantageRuleGroupResource) Create(
493
536
return
494
537
}
495
538
539
+ rules := utils .ListTypeAs [* fimRule ](ctx , plan .Rules , & resp .Diagnostics )
540
+ if resp .Diagnostics .HasError () {
541
+ return
542
+ }
543
+
496
544
resp .Diagnostics .Append (
497
- r .syncRules (ctx , rgType , plan . Rules , []* fimRule {}, plan .ID .ValueString ())... )
545
+ r .syncRules (ctx , rgType , rules , []* fimRule {}, plan .ID .ValueString ())... )
498
546
if resp .Diagnostics .HasError () {
499
547
return
500
548
}
@@ -510,7 +558,16 @@ func (r *filevantageRuleGroupResource) Create(
510
558
}
511
559
512
560
if len (rules ) > 0 {
513
- plan .Rules = rules
561
+ ruleList , diags := types .ListValueFrom (
562
+ ctx ,
563
+ types.ObjectType {AttrTypes : fimRule {}.attrTypes ()},
564
+ rules ,
565
+ )
566
+ resp .Diagnostics .Append (diags ... )
567
+ if resp .Diagnostics .HasError () {
568
+ return
569
+ }
570
+ plan .Rules = ruleList
514
571
}
515
572
516
573
resp .Diagnostics .Append (resp .State .Set (ctx , plan )... )
@@ -547,7 +604,6 @@ func (r *filevantageRuleGroupResource) Read(
547
604
}
548
605
549
606
assignRuleGroup (res , & state )
550
- state .LastUpdated = types .StringValue (time .Now ().Format (time .RFC850 ))
551
607
552
608
rules , diags := r .getRules (
553
609
ctx ,
@@ -560,7 +616,17 @@ func (r *filevantageRuleGroupResource) Read(
560
616
}
561
617
562
618
if len (rules ) > 0 {
563
- state .Rules = rules
619
+ ruleList , diags := types .ListValueFrom (
620
+ ctx ,
621
+ types.ObjectType {AttrTypes : fimRule {}.attrTypes ()},
622
+ & rules ,
623
+ )
624
+
625
+ resp .Diagnostics .Append (diags ... )
626
+ if resp .Diagnostics .HasError () {
627
+ return
628
+ }
629
+ state .Rules = ruleList
564
630
}
565
631
566
632
// Set refreshed state
@@ -615,12 +681,19 @@ func (r *filevantageRuleGroupResource) Update(
615
681
assignRuleGroup (res , & plan )
616
682
plan .LastUpdated = types .StringValue (time .Now ().Format (time .RFC850 ))
617
683
684
+ planRules := utils .ListTypeAs [* fimRule ](ctx , plan .Rules , & resp .Diagnostics )
685
+ stateRules := utils .ListTypeAs [* fimRule ](ctx , state .Rules , & resp .Diagnostics )
686
+
687
+ if resp .Diagnostics .HasError () {
688
+ return
689
+ }
690
+
618
691
resp .Diagnostics .Append (
619
692
r .syncRules (
620
693
ctx ,
621
694
plan .Type .ValueString (),
622
- plan . Rules ,
623
- state . Rules ,
695
+ planRules ,
696
+ stateRules ,
624
697
plan .ID .ValueString (),
625
698
)... )
626
699
if resp .Diagnostics .HasError () {
@@ -638,7 +711,16 @@ func (r *filevantageRuleGroupResource) Update(
638
711
}
639
712
640
713
if len (rules ) > 0 {
641
- plan .Rules = rules
714
+ ruleList , diags := types .ListValueFrom (
715
+ ctx ,
716
+ types.ObjectType {AttrTypes : fimRule {}.attrTypes ()},
717
+ rules ,
718
+ )
719
+ resp .Diagnostics .Append (diags ... )
720
+ if resp .Diagnostics .HasError () {
721
+ return
722
+ }
723
+ plan .Rules = ruleList
642
724
}
643
725
644
726
resp .Diagnostics .Append (
@@ -710,7 +792,13 @@ func (r *filevantageRuleGroupResource) ValidateConfig(
710
792
return
711
793
}
712
794
713
- for i , rule := range config .Rules {
795
+ rules := utils .ListTypeAs [* fimRule ](ctx , config .Rules , & resp .Diagnostics )
796
+
797
+ if resp .Diagnostics .HasError () {
798
+ return
799
+ }
800
+
801
+ for i , rule := range rules {
714
802
rPath := path .Root ("rules" ).AtListIndex (i )
715
803
716
804
if rgType == LinuxFiles || rgType == MacFiles || rgType == WindowsFiles {
@@ -1060,15 +1148,6 @@ func (r *filevantageRuleGroupResource) syncRules(
1060
1148
}
1061
1149
}
1062
1150
1063
- // panic(
1064
- // fmt.Sprintf(
1065
- // "rulesToCreate: %v rulesToDelete %v rulesToUpdate %v",
1066
- // rulesToCreate,
1067
- // rulesToDelete,
1068
- // rulesToUpdate,
1069
- // ),
1070
- // )
1071
-
1072
1151
diags .Append (r .createRules (ctx , ruleGroupType , rulesToCreate , ruleGroupID )... )
1073
1152
diags .Append (r .updateRules (ctx , ruleGroupType , rulesToUpdate , ruleGroupID )... )
1074
1153
diags .Append (r .deleteRules (ctx , rulesToDelete , ruleGroupID )... )
0 commit comments