From f9bdac59a5dcb02f3f1c6098341e30906c0c2750 Mon Sep 17 00:00:00 2001 From: Hila krut Date: Sun, 3 Nov 2024 09:42:01 +0200 Subject: [PATCH] add fix --- sysdig/common.go | 1 + ...ource_sysdig_secure_accept_posture_risk.go | 29 +++++++++++-------- website/docs/r/secure_posture_accept_risk.md | 8 +++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/sysdig/common.go b/sysdig/common.go index 40913444..d569bb59 100644 --- a/sysdig/common.go +++ b/sysdig/common.go @@ -28,6 +28,7 @@ const ( SchemaIsSystemKey = "is_system" SchemaUsernameKey = "username" SchemaAcceptPeriodKey = "accept_period" + SchemaEndTimeKey = "end_time" SchemaReasonKey = "reason" SchemaVersionKey = "version" SchemaLinkKey = "link" diff --git a/sysdig/resource_sysdig_secure_accept_posture_risk.go b/sysdig/resource_sysdig_secure_accept_posture_risk.go index 12969ae4..5089185a 100644 --- a/sysdig/resource_sysdig_secure_accept_posture_risk.go +++ b/sysdig/resource_sysdig_secure_accept_posture_risk.go @@ -61,7 +61,7 @@ func resourceSysdigSecureAcceptPostureRisk() *schema.Resource { }, SchemaExpiresAtKey: { Type: schema.TypeString, - Optional: true, + Computed: true, }, SchemaIsExpiredKey: { Type: schema.TypeBool, @@ -87,6 +87,11 @@ func resourceSysdigSecureAcceptPostureRisk() *schema.Resource { Type: schema.TypeString, Computed: true, }, + SchemaEndTimeKey: { + Type: schema.TypeString, + Optional: true, + Default: "", + }, }, } } @@ -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) @@ -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) diff --git a/website/docs/r/secure_posture_accept_risk.md b/website/docs/r/secure_posture_accept_risk.md index 61f25d6f..4d729e59 100644 --- a/website/docs/r/secure_posture_accept_risk.md +++ b/website/docs/r/secure_posture_accept_risk.md @@ -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" } ``` @@ -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. @@ -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