@@ -304,17 +304,17 @@ func (r *RulesetResource) ModifyPlan(ctx context.Context, req resource.ModifyPla
304
304
return
305
305
}
306
306
307
- ruleIDsByRef := make (map [string ]types. String )
307
+ rulesByRef := make (map [string ]* RulesetRulesModel )
308
308
309
309
stateRules , diags := state .Rules .AsStructSliceT (ctx )
310
310
resp .Diagnostics .Append (diags ... )
311
311
if resp .Diagnostics .HasError () {
312
312
return
313
313
}
314
314
315
- for _ , rule := range stateRules {
316
- if ref := rule .Ref .ValueString (); ref != "" {
317
- ruleIDsByRef [ref ] = rule . ID
315
+ for i := range stateRules {
316
+ if ref := stateRules [ i ] .Ref .ValueString (); ref != "" {
317
+ rulesByRef [ref ] = & stateRules [ i ]
318
318
}
319
319
}
320
320
@@ -324,17 +324,21 @@ func (r *RulesetResource) ModifyPlan(ctx context.Context, req resource.ModifyPla
324
324
return
325
325
}
326
326
327
- for i , rule := range planRules {
328
- // Do nothing if the rule's ID is a known planned value.
329
- if ! rule .ID .IsUnknown () {
330
- continue
331
- }
332
-
333
- // If the rule's ref matches a rule in the state, populate the planned
334
- // value of its ID with the corresponding ID from the state.
335
- if ref := rule .Ref .ValueString (); ref != "" {
336
- if id , ok := ruleIDsByRef [ref ]; ok {
337
- planRules [i ].ID = id
327
+ for i := range planRules {
328
+ if ref := planRules [i ].Ref .ValueString (); ref != "" {
329
+ if stateRule , ok := rulesByRef [ref ]; ok {
330
+ // If the rule's ref matches a rule from the state, populate its
331
+ // planned ID using the matching rule.
332
+ if planRules [i ].ID .IsUnknown () {
333
+ planRules [i ].ID = stateRule .ID
334
+ }
335
+
336
+ // If the rule's action is unchanged, populate its planned
337
+ // logging attribute using the matching rule from the state.
338
+ if planRules [i ].Logging .IsUnknown () &&
339
+ stateRule .Action .Equal (planRules [i ].Action ) {
340
+ planRules [i ].Logging = stateRule .Logging
341
+ }
338
342
}
339
343
}
340
344
}
0 commit comments