@@ -3,7 +3,6 @@ package sysdig
3
3
import (
4
4
"context"
5
5
"errors"
6
- "fmt"
7
6
"net/http"
8
7
"strconv"
9
8
"time"
@@ -51,7 +50,7 @@ func resourceSysdigSecureCustomPolicy() *schema.Resource {
51
50
ValidateDiagFunc : validateDiagFunc (validation .IntBetween (0 , 7 )),
52
51
},
53
52
"rules" : {
54
- Type : schema .TypeList ,
53
+ Type : schema .TypeSet ,
55
54
Optional : true ,
56
55
Elem : & schema.Resource {
57
56
Schema : map [string ]* schema.Schema {
@@ -100,11 +99,11 @@ func customPolicyFromResourceData(d *schema.ResourceData) v2.Policy {
100
99
101
100
policy .Rules = []* v2.PolicyRule {}
102
101
103
- rules := d .Get ("rules" ).([] interface {})
104
- for index := range rules {
102
+ for _ , ruleItr := range d .Get ("rules" ).(* schema. Set ). List () {
103
+ ruleInfo := ruleItr .( map [ string ] interface {})
105
104
rule := & v2.PolicyRule {
106
- Name : d . Get ( fmt . Sprintf ( "rules.%d. name", index )) .(string ),
107
- Enabled : d . Get ( fmt . Sprintf ( "rules.%d. enabled", index )) .(bool ),
105
+ Name : ruleInfo [ " name"] .(string ),
106
+ Enabled : ruleInfo [ " enabled"] .(bool ),
108
107
}
109
108
policy .Rules = append (policy .Rules , rule )
110
109
}
@@ -147,13 +146,14 @@ func customPolicyToResourceData(policy *v2.Policy, d *schema.ResourceData) {
147
146
}
148
147
149
148
func getPolicyRulesFromResourceData (d * schema.ResourceData ) []* v2.PolicyRule {
150
- rules := d .Get ("rules" ).([] interface {} )
149
+ rules := d .Get ("rules" ).(* schema. Set ). List ( )
151
150
policyRules := make ([]* v2.PolicyRule , len (rules ))
152
151
153
- for i , rule := range rules {
152
+ for i , ruleItr := range rules {
153
+ ruleInfo := ruleItr .(map [string ]interface {})
154
154
policyRules [i ] = & v2.PolicyRule {
155
- Name : rule .( map [ string ] interface {}) ["name" ].(string ),
156
- Enabled : rule .( map [ string ] interface {}) ["enabled" ].(bool ),
155
+ Name : ruleInfo ["name" ].(string ),
156
+ Enabled : ruleInfo ["enabled" ].(bool ),
157
157
}
158
158
}
159
159
0 commit comments