Skip to content

Commit 3c1bdc3

Browse files
authored
fix: check position index before updating CIS ruleset rule (IBM-Cloud#6472)
* fix: check position index before updating CIS ruleset rule Signed-off-by: Sirija Reddy <[email protected]> * fix: check position index before updating CIS ruleset rule Signed-off-by: Sirija Reddy <[email protected]> * add MaxItems --------- Signed-off-by: Sirija Reddy <[email protected]>
1 parent 55f8e59 commit 3c1bdc3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ibm/service/cis/resource_ibm_cis_ruleset_rule.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ func ResourceIBMCISRulesetRule() *schema.Resource {
333333
Type: schema.TypeList,
334334
Optional: true,
335335
Description: "Rules of the rulesets",
336+
MaxItems: 1,
336337
Elem: CISRulesetsRulesObject,
337338
},
338339
},
@@ -521,11 +522,13 @@ func ResourceIBMCISRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) e
521522
opt.SetEnabled(rulesetsRuleObject[CISRulesetsRuleActionEnabled].(bool))
522523
opt.SetExpression(rulesetsRuleObject[CISRulesetsRuleExpression].(string))
523524
opt.SetRef(rulesetsRuleObject[CISRulesetsRuleRef].(string))
524-
position, positionError := expandCISRulesetsRulesPositions(rulesetsRuleObject[CISRulesetsRulePosition])
525-
if positionError != nil {
526-
return flex.FmtErrorf("[ERROR] Error while updating the zone Ruleset %s", err)
525+
if d.HasChange(CISRulesetsRule + ".0." + CISRulesetsRulePosition) {
526+
position, positionError := expandCISRulesetsRulesPositions(rulesetsRuleObject[CISRulesetsRulePosition])
527+
if positionError != nil {
528+
return flex.FmtErrorf("[ERROR] Error while updating the zone Ruleset %s", positionError)
529+
}
530+
opt.SetPosition(&position)
527531
}
528-
opt.SetPosition(&position)
529532

530533
if v, ok := rulesetsRuleObject[CISRulesetsRuleRateLimit]; ok && v != nil {
531534
ratelimit, ratelimitErr := expandCISRulesetsRulesRateLimits(v)

0 commit comments

Comments
 (0)