Skip to content

Commit

Permalink
fix(synthetics): Add tags not fetched in newrelic_synthetics_cert_che…
Browse files Browse the repository at this point in the history
…ck_monitor

chore: fix codeQL alert
  • Loading branch information
abasha1234 authored and pranav-new-relic committed Apr 25, 2024
1 parent e8d467c commit ca3009b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions newrelic/resource_helpers_synthetics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package newrelic
import (
"encoding/base64"
"fmt"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -473,3 +474,23 @@ var syntheticsMonitorTagKeyToSchemaAttrMap = map[string]string{
"deviceOrientation": "device_orientation",
"deviceType": "device_type",
}

func getCertCheckMonitorValuesFromEntityTags(tags []entities.EntityTag) (domain string, daysUntilExpiration int) {
domain = ""
daysUntilExpiration = 0

for _, tag := range tags {

if tag.Key == "domain" {
domain = tag.Values[0]
}

if tag.Key == "daysUntilExpiration" {
// Parse string to integer
days := tag.Values[0]
daysUntilExpiration, _ = strconv.Atoi(days)
}
}

return domain, daysUntilExpiration
}
6 changes: 6 additions & 0 deletions newrelic/resource_newrelic_synthetics_cert_check_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ func resourceNewRelicSyntheticsCertCheckMonitorRead(ctx context.Context, d *sche
_ = d.Set("runtime_type_version", runtimeTypeVersion)
}

domain, daysUntilExpiration := getCertCheckMonitorValuesFromEntityTags(entity.GetTags())
if domain != "" && daysUntilExpiration != 0 {
_ = d.Set("domain", domain)
_ = d.Set("certificate_expiration", daysUntilExpiration)
}

}

return diag.FromErr(err)
Expand Down

0 comments on commit ca3009b

Please sign in to comment.