Skip to content

Commit e627406

Browse files
open the option to put expires_at
1 parent 7a92f57 commit e627406

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

sysdig/internal/client/v2/model_posture_control.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type AccepetPostureRiskRequest struct {
3131
Description string `json:"description"`
3232
Filter string `json:"filter"`
3333
Reason string `json:"reason"`
34-
ExpiresAt int64 `json:"expiresAt"`
34+
ExpiresAt string `json:"expiresAt"`
3535
}
3636

3737
type UpdateAccepetPostureRiskRequest struct {

sysdig/resource_sysdig_secure_accept_posture_risk.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sysdig
22

33
import (
44
"context"
5-
"fmt"
65
"strconv"
76
"time"
87

@@ -60,8 +59,8 @@ func resourceSysdigSecureAcceptPostureRisk() *schema.Resource {
6059
ValidateFunc: validation.StringInSlice([]string{"7 Days", "30 Days", "60 Days", "90 Days", "Custom", "Never"}, false),
6160
},
6261
SchemaExpiresAtKey: {
63-
Type: schema.TypeInt,
64-
Computed: true,
62+
Type: schema.TypeString,
63+
Optional: true,
6564
},
6665
SchemaIsExpiredKey: {
6766
Type: schema.TypeBool,
@@ -106,22 +105,23 @@ func resourceSysdigSecureAcceptPostureControlCreate(ctx context.Context, d *sche
106105
Filter: d.Get(SchemaFilterKey).(string),
107106
Reason: d.Get(SchemaReasonKey).(string),
108107
}
109-
108+
var expiresAt int64
110109
expiresIn := d.Get(SchemaExpiresInKey).(string)
111110
if expiresIn == "7 Days" {
112-
req.ExpiresAt = time.Now().AddDate(0, 0, 7).UTC().UnixMilli()
111+
expiresAt = time.Now().AddDate(0, 0, 7).UTC().UnixMilli()
113112
} else if expiresIn == "30 Days" {
114-
req.ExpiresAt = time.Now().AddDate(0, 0, 30).UTC().UnixMilli()
113+
expiresAt = time.Now().AddDate(0, 0, 30).UTC().UnixMilli()
115114
} else if expiresIn == "60 Days" {
116-
req.ExpiresAt = time.Now().AddDate(0, 0, 60).UTC().UnixMilli()
115+
expiresAt = time.Now().AddDate(0, 0, 60).UTC().UnixMilli()
117116
} else if expiresIn == "90 Days" {
118-
req.ExpiresAt = time.Now().AddDate(0, 0, 90).UTC().UnixMilli()
117+
expiresAt = time.Now().AddDate(0, 0, 90).UTC().UnixMilli()
119118
} else if expiresIn == "Never" {
120-
req.ExpiresAt = 0
119+
expiresAt = 0
121120
} else {
122-
req.ExpiresAt = d.Get(SchemaExpiresAtKey).(int64)
121+
t := d.Get(SchemaExpiresAtKey).(string)
122+
expiresAt, _ = strconv.ParseInt(t, 10, 64)
123123
}
124-
124+
req.ExpiresAt = strconv.FormatInt(expiresAt, 10)
125125
acceptance, errStatus, err := client.SaveAcceptPostureRisk(ctx, req)
126126
if err != nil {
127127
return diag.Errorf("Error creating accept risk. error status: %s err: %s", errStatus, err)
@@ -161,9 +161,13 @@ func resourceSysdigSecureAcceptPostureControlUpdate(ctx context.Context, d *sche
161161
millis = 0
162162
} else {
163163
req.Acceptance.AcceptPeriod = "Custom"
164-
req.Acceptance.ExpiresAt = d.Get(SchemaExpiresAtKey).(string)
164+
t := d.Get(SchemaExpiresAtKey).(string)
165+
millis, err = strconv.ParseInt(t, 10, 64)
166+
if err != nil {
167+
millis = time.Now().AddDate(0, 0, 30).UTC().UnixMilli()
168+
}
165169
}
166-
req.Acceptance.ExpiresAt = fmt.Sprintf("%d", millis)
170+
req.Acceptance.ExpiresAt = strconv.FormatInt(millis, 10)
167171
req.Acceptance.Description = d.Get(SchemaDescriptionKey).(string)
168172
req.Acceptance.Reason = d.Get(SchemaReasonKey).(string)
169173

@@ -224,11 +228,8 @@ func resourceSysdigSecureAcceptPostureControlRead(ctx context.Context, d *schema
224228
if err != nil {
225229
return diag.FromErr(err)
226230
}
227-
expiresAt, err := strconv.ParseInt(acceptance.Data.ExpiresAt, 10, 64)
228-
if err != nil {
229-
return diag.FromErr(err)
230-
}
231-
err = d.Set(SchemaExpiresAtKey, expiresAt)
231+
232+
err = d.Set(SchemaExpiresAtKey, acceptance.Data.ExpiresAt)
232233
if err != nil {
233234
return diag.FromErr(err)
234235
}

website/docs/r/secure_posture_accept_risk.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ resource "sysdig_secure_posture_accept_risk" "accept_risk_resource" {
3030
expires_in = "30 Days"
3131
filter = "name in ('system:controller:daemon-set-s') and kind in ('ClusterRole')"
3232
}
33+
34+
35+
resource "sysdig_secure_posture_accept_risk" "scheduler_set_to_loopback_bind_address" {
36+
description = "This is custom risk acceptance for scheduler_set_to_loopback_bind_address"
37+
control_name = "Scheduler - Set to Loopback bind-address"
38+
reason = "Custom"
39+
expires_in = "Custom"
40+
expires_at = "1730293523000"
41+
zone_name = "Entire Infrastructure"
42+
}
3343
```
3444

3545
## Argument Reference
@@ -53,7 +63,7 @@ resource "sysdig_secure_posture_accept_risk" "accept_risk_resource" {
5363
- `90 Days`
5464
- `Custom`
5565
- `Never`
56-
- `expires_at` - (Computed) The timestamp indicating when the acceptance expires, in UTC time format (milliseconds since epoch).
66+
- `expires_at` - (Optional) This timestamp indicates when the acceptance expires, formatted in UTC time (milliseconds since epoch). If you choose expires_in=Custom, you must provide expires_at, which specifies the expiration date in milliseconds.
5767
- `is_expired` - (Computed) Indicates whether the acceptance is expired.
5868
- `acceptance_date` - (Computed) The date when the risk was accepted.
5969
- `username` - (Computed) The username of the user who accepted the risk.

0 commit comments

Comments
 (0)