Skip to content

Commit

Permalink
add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hila-krut-sysdig committed Nov 3, 2024
1 parent e451672 commit f9bdac5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions sysdig/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
SchemaIsSystemKey = "is_system"
SchemaUsernameKey = "username"
SchemaAcceptPeriodKey = "accept_period"
SchemaEndTimeKey = "end_time"
SchemaReasonKey = "reason"
SchemaVersionKey = "version"
SchemaLinkKey = "link"
Expand Down
29 changes: 17 additions & 12 deletions sysdig/resource_sysdig_secure_accept_posture_risk.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func resourceSysdigSecureAcceptPostureRisk() *schema.Resource {
},
SchemaExpiresAtKey: {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
SchemaIsExpiredKey: {
Type: schema.TypeBool,
Expand All @@ -87,6 +87,11 @@ func resourceSysdigSecureAcceptPostureRisk() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
SchemaEndTimeKey: {
Type: schema.TypeString,
Optional: true,
Default: "",
},
},
}
}
Expand All @@ -106,26 +111,26 @@ func resourceSysdigSecureAcceptPostureControlCreate(ctx context.Context, d *sche
Filter: d.Get(SchemaFilterKey).(string),
Reason: d.Get(SchemaReasonKey).(string),
}
var expiresAt int64
var endTime int64
expiresIn := d.Get(SchemaExpiresInKey).(string)
if expiresIn == "7 Days" {
expiresAt = time.Now().AddDate(0, 0, 7).UTC().UnixMilli()
endTime = time.Now().AddDate(0, 0, 7).UTC().UnixMilli()
} else if expiresIn == "30 Days" {
expiresAt = time.Now().AddDate(0, 0, 30).UTC().UnixMilli()
endTime = time.Now().AddDate(0, 0, 30).UTC().UnixMilli()
} else if expiresIn == "60 Days" {
expiresAt = time.Now().AddDate(0, 0, 60).UTC().UnixMilli()
endTime = time.Now().AddDate(0, 0, 60).UTC().UnixMilli()
} else if expiresIn == "90 Days" {
expiresAt = time.Now().AddDate(0, 0, 90).UTC().UnixMilli()
endTime = time.Now().AddDate(0, 0, 90).UTC().UnixMilli()
} else if expiresIn == "Never" {
expiresAt = 0
endTime = 0
} else {
t := d.Get(SchemaExpiresAtKey).(string)
expiresAt, _ = strconv.ParseInt(t, 10, 64)
t := d.Get(SchemaEndTimeKey).(string)
endTime, _ = strconv.ParseInt(t, 10, 64)
}
if expiresAt <= time.Now().UTC().UnixMilli() {
if endTime <= time.Now().UTC().UnixMilli() {
return diag.Errorf("Error creating accept risk. error status: %s err: %s", "ExpiresAt must be in the future", fmt.Errorf("ExpiresAt must be in the future"))
}
req.ExpiresAt = strconv.FormatInt(expiresAt, 10)
req.ExpiresAt = strconv.FormatInt(endTime, 10)
acceptance, errStatus, err := client.SaveAcceptPostureRisk(ctx, req)
if err != nil {
return diag.Errorf("Error creating accept risk. error status: %s err: %s", errStatus, err)
Expand Down Expand Up @@ -165,7 +170,7 @@ func resourceSysdigSecureAcceptPostureControlUpdate(ctx context.Context, d *sche
millis = 0
} else {
req.Acceptance.AcceptPeriod = "Custom"
t := d.Get(SchemaExpiresAtKey).(string)
t := d.Get(SchemaEndTimeKey).(string)
millis, err = strconv.ParseInt(t, 10, 64)
if millis <= time.Now().UTC().UnixMilli() {
return diag.Errorf("Error updating accept risk. ID: %s, error status: %s err: %s", req.AcceptanceID, "ExpiresAt must be in the future", err)
Expand Down
8 changes: 5 additions & 3 deletions website/docs/r/secure_posture_accept_risk.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "sysdig_secure_posture_accept_risk" "scheduler_set_to_loopback_bind_add
control_name = "Scheduler - Set to Loopback bind-address"
reason = "Custom"
expires_in = "Custom"
expires_at = "1730293523000"
end_time = "1730293523000"
zone_name = "Entire Infrastructure"
}
```
Expand Down Expand Up @@ -90,7 +90,9 @@ resource "sysdig_secure_posture_accept_risk" "scheduler_set_to_loopback_bind_add
- `90 Days`
- `Custom`
- `Never`
- `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.
- `expires_at` - (Computed) This timestamp indicates when the acceptance expires, formatted in UTC time (milliseconds since epoch).
- `end_time` - (Optional) This timestamp indicates the custom time, when the acceptance expires, formatted in UTC time (milliseconds since epoch).
If you choose expires_in=Custom, you should provide future end_time, which specifies the expiration date in milliseconds.
- `is_expired` - (Computed) Indicates whether the acceptance is expired.
- `acceptance_date` - (Computed) The date when the risk was accepted.
- `username` - (Computed) The username of the user who accepted the risk.
Expand All @@ -107,7 +109,7 @@ In addition to all arguments above, the following attributes are exported:

## Import

Posture custom control can be imported using the ID, e.g.
Posture accept risk can be imported using the ID, e.g.

```
$ terraform import sysdig_secure_posture_accept_risk.example c 12345
Expand Down

0 comments on commit f9bdac5

Please sign in to comment.