From ca3009b63c764eaf23fd0ce503372337a53a23d6 Mon Sep 17 00:00:00 2001 From: abasha1234 Date: Thu, 25 Apr 2024 15:47:50 +0530 Subject: [PATCH] fix(synthetics): Add tags not fetched in newrelic_synthetics_cert_check_monitor chore: fix codeQL alert --- newrelic/resource_helpers_synthetics.go | 21 +++++++++++++++++++ ..._newrelic_synthetics_cert_check_monitor.go | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/newrelic/resource_helpers_synthetics.go b/newrelic/resource_helpers_synthetics.go index b50005cd84..51a9136bc8 100644 --- a/newrelic/resource_helpers_synthetics.go +++ b/newrelic/resource_helpers_synthetics.go @@ -3,6 +3,7 @@ package newrelic import ( "encoding/base64" "fmt" + "strconv" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -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 +} diff --git a/newrelic/resource_newrelic_synthetics_cert_check_monitor.go b/newrelic/resource_newrelic_synthetics_cert_check_monitor.go index 4935469b53..2f25ee591c 100644 --- a/newrelic/resource_newrelic_synthetics_cert_check_monitor.go +++ b/newrelic/resource_newrelic_synthetics_cert_check_monitor.go @@ -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)