Skip to content

Commit

Permalink
fix: time parse error for expiry field (#332)
Browse files Browse the repository at this point in the history
* fix: time pasre error for expiry field

Signed-off-by: Darren Murray <darren.murray@lacework.net>

* test: no expiry test

Signed-off-by: Darren Murray <darren.murray@lacework.net>
  • Loading branch information
dmurray-lacework authored Jun 23, 2022
1 parent 5550234 commit 8c691ef
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
37 changes: 36 additions & 1 deletion examples/resource_lacework_vulnerability_exception_host/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ resource "lacework_vulnerability_exception_host" "example" {
name = var.name
description = var.description
enabled = true
expiry = "2023-06-06T15:55:15Z"
expiry = var.expiry
reason = "Accepted Risk"
vulnerability_criteria {
severities = ["Critical"]
Expand All @@ -37,6 +37,41 @@ resource "lacework_vulnerability_exception_host" "example" {
}
}

resource "lacework_vulnerability_exception_host" "no_expiry" {
name = var.name
description = var.description
enabled = true
reason = "Accepted Risk"
vulnerability_criteria {
severities = ["Critical"]
cves = var.cves
package {
name = var.package_name
version = var.package_version
}
package {
name = "myPackage"
version = "2.0.0"
}
package {
name = "myOtherPackage"
version = "1.0.0"
}
fixable = true
}
resource_scope {
hostnames = ["host1", "host2"]
cluster_names = ["clust-abc", "clust-xyz"]
external_ips = ["210.12.100.5"]
namespaces = ["namespace1", "namespace2"]
}
}

variable "expiry" {
type = string
default = "2023-06-06T15:55:15Z"
}

variable "name" {
type = string
default = "Terraform Host Vulnerability Exception"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func TestVulnerabilityExceptionHostCreate(t *testing.T) {
assert.Equal(t, "[CVE-2016-9840 CVE-2018-14599 CVE-2018-6942]", actualCves)
assert.Equal(t, "[map[name:myOtherPackage version:1.0.0] map[name:myPackage version:1.0.0] map[name:myPackage version:2.0.0]]", actualPackages)

noexpiry := GetSpecificIDFromTerraResults(2, create)
assert.NotEmpty(t, noexpiry)

// Update Vulnerability Exception
terraformOptions.Vars = map[string]interface{}{
"name": "Terraform Vulnerability Exception Host Test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func resourceLaceworkVulnerabilityExceptionContainerCreate(d *schema.ResourceDat
}
)

if d.Get("expiry") != nil {
if d.Get("expiry") != nil && d.Get("expiry") != "" {
expiryTime, err := time.Parse(time.RFC3339, d.Get("expiry").(string))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unable to parse expiry time %s", d.Get("expiry").(string)))
Expand Down Expand Up @@ -345,7 +345,7 @@ func resourceLaceworkVulnerabilityExceptionContainerUpdate(d *schema.ResourceDat
}
)

if d.Get("expiry") != nil {
if d.Get("expiry") != nil && d.Get("expiry") != "" {
expiryTime, err := time.Parse(time.RFC3339, d.Get("expiry").(string))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unable to parse expiry time %s", d.Get("expiry").(string)))
Expand Down
4 changes: 2 additions & 2 deletions lacework/resource_lacework_vulnerability_exception_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func resourceLaceworkVulnerabilityExceptionHostCreate(d *schema.ResourceData, me
Fixable: d.Get("vulnerability_criteria.0.fixable").(bool),
}
)
if d.Get("expiry") != nil {
if d.Get("expiry") != nil && d.Get("expiry") != "" {
expiryTime, err := time.Parse(time.RFC3339, d.Get("expiry").(string))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unable to parse expiry time %s", d.Get("expiry").(string)))
Expand Down Expand Up @@ -332,7 +332,7 @@ func resourceLaceworkVulnerabilityExceptionHostUpdate(d *schema.ResourceData, me
}
)

if d.Get("expiry") != nil {
if d.Get("expiry") != nil && d.Get("expiry") != "" {
expiryTime, err := time.Parse(time.RFC3339, d.Get("expiry").(string))
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unable to parse expiry time %s", d.Get("expiry").(string)))
Expand Down

0 comments on commit 8c691ef

Please sign in to comment.