| 
4 | 4 | 	"context"  | 
5 | 5 | 	"encoding/json"  | 
6 | 6 | 	"errors"  | 
 | 7 | +	"fmt"  | 
7 | 8 | 	"strconv"  | 
8 | 9 | 	"strings"  | 
9 | 10 | 	"time"  | 
@@ -146,10 +147,55 @@ func resourceSysdigRuleFalcoRead(ctx context.Context, d *schema.ResourceData, me  | 
146 | 147 | 	if rule.Details.Append != nil {  | 
147 | 148 | 		_ = d.Set("append", *rule.Details.Append)  | 
148 | 149 | 	}  | 
 | 150 | +	if err := updateResourceDataExceptions(d, rule.Details.Exceptions); err != nil {  | 
 | 151 | +		return diag.FromErr(err)  | 
 | 152 | +	}  | 
 | 153 | + | 
 | 154 | +	return nil  | 
 | 155 | +}  | 
 | 156 | + | 
 | 157 | +func updateResourceDataExceptions(d *schema.ResourceData, ruleExceptions []*secure.Exception) error {  | 
 | 158 | +	exceptions := make([]any, 0, len(ruleExceptions))  | 
 | 159 | +	for _, exception := range ruleExceptions {  | 
 | 160 | +		valuesData, err := json.Marshal(exception.Values)  | 
 | 161 | +		if err != nil {  | 
 | 162 | +			return fmt.Errorf("error marshalling exception values '%+v': %s", exception.Values, err)  | 
 | 163 | +		}  | 
 | 164 | +		fields, err := fieldOrCompsToStringSlice(exception.Fields)  | 
 | 165 | +		if err != nil {  | 
 | 166 | +			return fmt.Errorf("error converting exception fields '%+v': %s", exception.Fields, err)  | 
 | 167 | +		}  | 
 | 168 | +		comps, err := fieldOrCompsToStringSlice(exception.Comps)  | 
 | 169 | +		if err != nil {  | 
 | 170 | +			return fmt.Errorf("error converting exception comps '%+v': %s", exception.Comps, err)  | 
 | 171 | +		}  | 
149 | 172 | 
 
  | 
 | 173 | +		exceptions = append(exceptions, map[string]any{  | 
 | 174 | +			"name":   exception.Name,  | 
 | 175 | +			"comps":  comps,  | 
 | 176 | +			"values": string(valuesData),  | 
 | 177 | +			"fields": fields,  | 
 | 178 | +		})  | 
 | 179 | +	}  | 
 | 180 | +	_ = d.Set("exceptions", exceptions)  | 
150 | 181 | 	return nil  | 
151 | 182 | }  | 
152 | 183 | 
 
  | 
 | 184 | +func fieldOrCompsToStringSlice(fields any) ([]string, error) {  | 
 | 185 | +	elements := []string{}  | 
 | 186 | +	switch t := fields.(type) {  | 
 | 187 | +	case []interface{}:  | 
 | 188 | +		for _, field := range t {  | 
 | 189 | +			elements = append(elements, field.(string))  | 
 | 190 | +		}  | 
 | 191 | +	case string:  | 
 | 192 | +		elements = append(elements, t)  | 
 | 193 | +	default:  | 
 | 194 | +		return nil, fmt.Errorf("unexpected type: %T", t)  | 
 | 195 | +	}  | 
 | 196 | +	return elements, nil  | 
 | 197 | +}  | 
 | 198 | + | 
153 | 199 | func resourceSysdigRuleFalcoUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {  | 
154 | 200 | 	client, err := meta.(SysdigClients).sysdigSecureClient()  | 
155 | 201 | 	if err != nil {  | 
 | 
0 commit comments