@@ -24,7 +24,6 @@ type securityMonitoringSuppressionModel struct {
24
24
Name types.String `tfsdk:"name"`
25
25
Description types.String `tfsdk:"description"`
26
26
Enabled types.Bool `tfsdk:"enabled"`
27
- StartDate types.String `tfsdk:"start_date"`
28
27
ExpirationDate types.String `tfsdk:"expiration_date"`
29
28
RuleQuery types.String `tfsdk:"rule_query"`
30
29
SuppressionQuery types.String `tfsdk:"suppression_query"`
@@ -69,10 +68,6 @@ func (r *securityMonitoringSuppressionResource) Schema(_ context.Context, _ reso
69
68
Required : true ,
70
69
Description : "Whether the suppression rule is enabled." ,
71
70
},
72
- "start_date" : schema.StringAttribute {
73
- Optional : true ,
74
- Description : "A RFC3339 timestamp giving a start date for the suppression rule. Before this date, it doesn't suppress signals." ,
75
- },
76
71
"expiration_date" : schema.StringAttribute {
77
72
Optional : true ,
78
73
Description : "A RFC3339 timestamp giving an expiration date for the suppression rule. After this date, it won't suppress signals anymore." ,
@@ -209,7 +204,7 @@ func (r *securityMonitoringSuppressionResource) Delete(ctx context.Context, requ
209
204
}
210
205
211
206
func (r * securityMonitoringSuppressionResource ) buildCreateSecurityMonitoringSuppressionPayload (state * securityMonitoringSuppressionModel ) (* datadogV2.SecurityMonitoringSuppressionCreateRequest , error ) {
212
- name , description , enabled , startDate , expirationDate , ruleQuery , suppressionQuery , dataExclusionQuery , err := r .extractSuppressionAttributesFromResource (state )
207
+ name , description , enabled , expirationDate , ruleQuery , suppressionQuery , dataExclusionQuery , err := r .extractSuppressionAttributesFromResource (state )
213
208
214
209
if err != nil {
215
210
return nil , err
@@ -219,15 +214,14 @@ func (r *securityMonitoringSuppressionResource) buildCreateSecurityMonitoringSup
219
214
attributes .SuppressionQuery = suppressionQuery
220
215
attributes .DataExclusionQuery = dataExclusionQuery
221
216
attributes .Description = description
222
- attributes .StartDate = startDate
223
217
attributes .ExpirationDate = expirationDate
224
218
225
219
data := datadogV2 .NewSecurityMonitoringSuppressionCreateData (* attributes , datadogV2 .SECURITYMONITORINGSUPPRESSIONTYPE_SUPPRESSIONS )
226
220
return datadogV2 .NewSecurityMonitoringSuppressionCreateRequest (* data ), nil
227
221
}
228
222
229
223
func (r * securityMonitoringSuppressionResource ) buildUpdateSecurityMonitoringSuppressionPayload (state * securityMonitoringSuppressionModel ) (* datadogV2.SecurityMonitoringSuppressionUpdateRequest , error ) {
230
- name , description , enabled , startDate , expirationDate , ruleQuery , suppressionQuery , dataExclusionQuery , err := r .extractSuppressionAttributesFromResource (state )
224
+ name , description , enabled , expirationDate , ruleQuery , suppressionQuery , dataExclusionQuery , err := r .extractSuppressionAttributesFromResource (state )
231
225
232
226
if err != nil {
233
227
return nil , err
@@ -237,11 +231,6 @@ func (r *securityMonitoringSuppressionResource) buildUpdateSecurityMonitoringSup
237
231
attributes .SetName (name )
238
232
attributes .Description = description
239
233
attributes .SetEnabled (enabled )
240
- if startDate != nil {
241
- attributes .SetStartDate (* startDate )
242
- } else {
243
- attributes .SetStartDateNil ()
244
- }
245
234
if expirationDate != nil {
246
235
attributes .SetExpirationDate (* expirationDate )
247
236
} else {
@@ -265,7 +254,7 @@ func (r *securityMonitoringSuppressionResource) buildUpdateSecurityMonitoringSup
265
254
return datadogV2 .NewSecurityMonitoringSuppressionUpdateRequest (* data ), nil
266
255
}
267
256
268
- func (r * securityMonitoringSuppressionResource ) extractSuppressionAttributesFromResource (state * securityMonitoringSuppressionModel ) (string , * string , bool , * int64 , * int64 , string , * string , * string , error ) {
257
+ func (r * securityMonitoringSuppressionResource ) extractSuppressionAttributesFromResource (state * securityMonitoringSuppressionModel ) (string , * string , bool , * int64 , string , * string , * string , error ) {
269
258
// Mandatory fields
270
259
271
260
name := state .Name .ValueString ()
@@ -277,36 +266,21 @@ func (r *securityMonitoringSuppressionResource) extractSuppressionAttributesFrom
277
266
description := state .Description .ValueStringPointer ()
278
267
suppressionQuery := state .SuppressionQuery .ValueStringPointer ()
279
268
dataExclusionQuery := state .DataExclusionQuery .ValueStringPointer ()
280
-
281
- var startDate * int64
282
-
283
- if tfStartDate := state .StartDate .ValueStringPointer (); tfStartDate != nil {
284
- startDateTime , err := time .Parse (time .RFC3339 , * tfStartDate )
285
-
286
- if err != nil {
287
- return "" , nil , false , nil , nil , "" , nil , nil , err
288
- }
289
-
290
- startDateTimestamp := startDateTime .UnixMilli ()
291
- startDate = & startDateTimestamp
292
-
293
- }
294
-
295
269
var expirationDate * int64
296
270
297
271
if tfExpirationDate := state .ExpirationDate .ValueStringPointer (); tfExpirationDate != nil {
298
272
expirationDateTime , err := time .Parse (time .RFC3339 , * tfExpirationDate )
299
273
300
274
if err != nil {
301
- return "" , nil , false , nil , nil , "" , nil , nil , err
275
+ return "" , nil , false , nil , "" , nil , nil , err
302
276
}
303
277
304
278
expirationDateTimestamp := expirationDateTime .UnixMilli ()
305
279
expirationDate = & expirationDateTimestamp
306
280
307
281
}
308
282
309
- return name , description , enabled , startDate , expirationDate , ruleQuery , suppressionQuery , dataExclusionQuery , nil
283
+ return name , description , enabled , expirationDate , ruleQuery , suppressionQuery , dataExclusionQuery , nil
310
284
}
311
285
312
286
func (r * securityMonitoringSuppressionResource ) updateStateFromResponse (ctx context.Context , state * securityMonitoringSuppressionModel , res * datadogV2.SecurityMonitoringSuppressionResponse ) {
@@ -339,35 +313,21 @@ func (r *securityMonitoringSuppressionResource) updateStateFromResponse(ctx cont
339
313
state .DataExclusionQuery = types .StringNull ()
340
314
}
341
315
342
- // For the StartDate and the ExpirationDate
343
- // The API only requires a millisecond timestamp, it does not care about timezones.
344
- // If the timestamp string written by the user has the same millisecond value as the one returned by the API,
345
- // we keep the user-defined one in the state.
346
- if attributes .StartDate != nil {
347
- responseStartDate := time .UnixMilli (* attributes .StartDate ).UTC ()
348
- startDate := responseStartDate .Format (time .RFC3339 )
349
-
350
- if userStartDateStr := state .StartDate .ValueString (); userStartDateStr != "" {
351
- if userStartDate , err := time .Parse (time .RFC3339 , userStartDateStr ); err == nil {
352
- if userStartDate .UnixMilli () == responseStartDate .UnixMilli () {
353
- startDate = userStartDateStr
354
- }
355
- }
356
- }
357
- state .StartDate = types .StringValue (startDate )
358
- }
359
-
360
316
if attributes .ExpirationDate != nil {
361
317
responseExpirationDate := time .UnixMilli (* attributes .ExpirationDate ).UTC ()
362
318
expirationDate := responseExpirationDate .Format (time .RFC3339 )
363
319
364
320
if userExpirationDateStr := state .ExpirationDate .ValueString (); userExpirationDateStr != "" {
365
321
if userExpirationDate , err := time .Parse (time .RFC3339 , userExpirationDateStr ); err == nil {
322
+ // The API only requires a millisecond timestamp, it does not care about timezones.
323
+ // If the timestamp string written by the user has the same millisecond value as the one returned by the API,
324
+ // we keep the user-defined one in the state.
366
325
if userExpirationDate .UnixMilli () == responseExpirationDate .UnixMilli () {
367
326
expirationDate = userExpirationDateStr
368
327
}
369
328
}
370
329
}
330
+
371
331
state .ExpirationDate = types .StringValue (expirationDate )
372
332
}
373
333
}
0 commit comments