Skip to content

Commit 0f2931a

Browse files
feat(cis): add rules_to_skip in ibm_cis_ruleset_rule (#6441)
* deleted unused log statement * update the schema to have rules_to_skip * update the rules-to-skip schema and add expand and flattening logic * make ruleset_id and rule_ids required field & update docs * revert the code change in iam service * add schema in datasource and update the datasource related doc
1 parent ad25c97 commit 0f2931a

File tree

7 files changed

+100
-3
lines changed

7 files changed

+100
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/IBM/logs-go-sdk v0.4.0
2828
github.com/IBM/logs-router-go-sdk v1.0.8
2929
github.com/IBM/mqcloud-go-sdk v0.3.0
30-
github.com/IBM/networking-go-sdk v0.51.11
30+
github.com/IBM/networking-go-sdk v0.51.12
3131
github.com/IBM/platform-services-go-sdk v0.86.1
3232
github.com/IBM/project-go-sdk v0.3.5
3333
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ github.com/IBM/logs-router-go-sdk v1.0.8 h1:MU1TdYNdVbvVTUXeqeYPItu6BoiSV/NMN49y
147147
github.com/IBM/logs-router-go-sdk v1.0.8/go.mod h1:tCN2vFgu5xG0ob9iJcxi5M4bJ6mWmu3nhmRPnvlwev0=
148148
github.com/IBM/mqcloud-go-sdk v0.3.0 h1:zuRe+lu6IwIzsBsmoVKZT4JgX+GxH5PJG06r5y5Xnh4=
149149
github.com/IBM/mqcloud-go-sdk v0.3.0/go.mod h1:7zigCUz6k3eRrNE8KOcDkY72oPppEmoQifF+SB0NPRM=
150-
github.com/IBM/networking-go-sdk v0.51.11 h1:l+yMXcO9GDcb7JU9jl8riUOXjnHTvIKSLnXYFlYlKXo=
151-
github.com/IBM/networking-go-sdk v0.51.11/go.mod h1:TAXWyBUk3C3R7aS1m84EfKdnDcBMZMAClwLfDj/SYZc=
150+
github.com/IBM/networking-go-sdk v0.51.12 h1:2qv6neG8msFR1dtf9v+rbaC2gIkw9HnzohvQpgVye5w=
151+
github.com/IBM/networking-go-sdk v0.51.12/go.mod h1:TAXWyBUk3C3R7aS1m84EfKdnDcBMZMAClwLfDj/SYZc=
152152
github.com/IBM/platform-services-go-sdk v0.86.1 h1:ngBpaXvUF3gmLvbU1Z4lX1wowOSYgGoKBEBaR/urt30=
153153
github.com/IBM/platform-services-go-sdk v0.86.1/go.mod h1:aGD045m6I8pfcB77wft8w2cHqWOJjcM3YSSV55BX0Js=
154154
github.com/IBM/project-go-sdk v0.3.5 h1:L+YClFUa14foS0B/hOOY9n7sIdsT5/XQicnXOyJSpyM=

ibm/service/cis/data_source_ibm_cis_rulesets.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const (
6565
CISRulesetOverridesScoreThreshold = "score_threshold"
6666
CISRulesetsRulePhases = "phases"
6767
CISRulesetsRuleProducts = "products"
68+
CISRulesToSkip = "rules_to_skip"
6869
)
6970

7071
var CISResponseObject = &schema.Resource{
@@ -271,6 +272,28 @@ var CISResponseObject = &schema.Resource{
271272
},
272273
},
273274
},
275+
CISRulesToSkip: {
276+
Type: schema.TypeList,
277+
Computed: true,
278+
Description: "A list of ruleset mappings, where each element is a map of ruleset_id and its associated rule_ids",
279+
Elem: &schema.Resource{
280+
Schema: map[string]*schema.Schema{
281+
"ruleset_id": {
282+
Type: schema.TypeString,
283+
Computed: true,
284+
Description: "The ruleset identifier",
285+
},
286+
"rule_ids": {
287+
Type: schema.TypeList,
288+
Computed: true,
289+
Description: "A list of rule IDs to be skipped",
290+
Elem: &schema.Schema{
291+
Type: schema.TypeString,
292+
},
293+
},
294+
},
295+
},
296+
},
274297
},
275298
},
276299
},
@@ -561,6 +584,20 @@ func flattenCISRulesetsRuleActionParameters(rulesetsRuleActionParameterObj *rule
561584
resultOutput[CISRulesetOverrides] = []map[string]interface{}{flattenCISRulesetsRuleActionParameterOverrides}
562585
}
563586

587+
if rulesToSkip := rulesetsRuleActionParameterObj.Rules; rulesToSkip != nil && len(rulesToSkip) > 0 {
588+
flattenedRulesToSkip := make([]map[string]interface{}, 0, len(rulesToSkip))
589+
590+
for rulesetID, ruleIDs := range rulesToSkip {
591+
entry := map[string]interface{}{
592+
"ruleset_id": rulesetID,
593+
"rule_ids": ruleIDs,
594+
}
595+
flattenedRulesToSkip = append(flattenedRulesToSkip, entry)
596+
}
597+
598+
resultOutput[CISRulesToSkip] = flattenedRulesToSkip
599+
}
600+
564601
return resultOutput
565602
}
566603

ibm/service/cis/resource_ibm_cis_ruleset.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,32 @@ func expandCISRulesetsRulesActionParameters(obj interface{}) rulesetsv1.ActionPa
597597
productsList := flex.ExpandStringList(products)
598598
actionParameterRespObj.Products = productsList
599599

600+
if v, ok := actionParameterObj[CISRulesToSkip].([]interface{}); ok && len(v) > 0 {
601+
rulesToSkipMap := make(map[string][]string)
602+
603+
for _, item := range v {
604+
if item == nil {
605+
continue
606+
}
607+
entry := item.(map[string]interface{})
608+
609+
rulesetID, _ := entry["ruleset_id"].(string)
610+
if rulesetID == "" {
611+
continue
612+
}
613+
614+
ruleIDsIface, _ := entry["rule_ids"].([]interface{})
615+
ruleIDs := make([]string, 0, len(ruleIDsIface))
616+
for _, ruleID := range ruleIDsIface {
617+
ruleIDs = append(ruleIDs, fmt.Sprint(ruleID))
618+
}
619+
620+
rulesToSkipMap[rulesetID] = ruleIDs
621+
}
622+
623+
actionParameterRespObj.Rules = rulesToSkipMap
624+
}
625+
600626
finalResponse := make([]rulesetsv1.ActionParameters, 0)
601627

602628
overrideObj := rulesetsv1.Overrides{}

ibm/service/cis/resource_ibm_cis_ruleset_rule.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ var CISRulesetsRulesObject = &schema.Resource{
178178
},
179179
},
180180
},
181+
CISRulesToSkip: {
182+
Type: schema.TypeList,
183+
Optional: true,
184+
Description: "A list of ruleset mappings, where each element is a map of ruleset_id and its associated rule_ids",
185+
Elem: &schema.Resource{
186+
Schema: map[string]*schema.Schema{
187+
"ruleset_id": {
188+
Type: schema.TypeString,
189+
Required: true,
190+
Description: "The ruleset identifier",
191+
},
192+
"rule_ids": {
193+
Type: schema.TypeList,
194+
Required: true,
195+
Description: "A list of rule IDs to be skipped",
196+
Elem: &schema.Schema{
197+
Type: schema.TypeString,
198+
},
199+
},
200+
},
201+
},
202+
},
181203
},
182204
},
183205
},

website/docs/d/cis_rulesets.html.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Extra attribute references when `ruleset_id` is provided.
8888
- `content` (String) Content of the response.
8989
- `content_type` (string) Content type of the response.
9090
- `status_code` (Int) Status code returned by the API.
91+
- `rules_to_skip` (Optional, List) Rules to be skipped when action is `skip`
92+
Nested scheme of `rules_to_skip`
93+
- `ruleset_id` (Required, String) Id of the Ruleset
94+
- `rule_ids` (Required, List) List of rule-ids
95+
9196
- `rate_limit` (Map) Ratelimit of the rule
9297

9398
Nested scheme of `rate_limit`

website/docs/r/cis_ruleset_rule.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ Review the argument references that you can specify for your resource.
157157
- `category` (Required, String) Category of the rule.
158158
- `enabled` (Optional, Boolean) Enables/Disables the rule.
159159
- `action` (Optional, String) Action of the rule.
160+
161+
- `rules_to_skip` (Optional, List) Rules to be skipped when action is `skip`
162+
163+
Nested scheme of `rules_to_skip`
164+
- `ruleset_id` (Required, String) Id of the Ruleset
165+
- `rule_ids` (Required, List) List of rule-ids
166+
160167
- `position` (Optional, List). You can use only one of the before, after, and index fields at a time. It is used to update the positing of the existing rule.
161168
- `index` (Optional, String) Index of the rule to be added.
162169
- `before` (Optional, String) ID of the rule before which the new rule will be added.

0 commit comments

Comments
 (0)