From a704ca5d34cce4d404f753d2084a30ef0daee494 Mon Sep 17 00:00:00 2001 From: Ahmed Basha <127721368+abasha1234@users.noreply.github.com> Date: Thu, 25 Apr 2024 18:38:59 +0530 Subject: [PATCH] fix(synthetics): Add missing tags for newrelic_synthetics_cert_check_monitor (#2642) --- 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 f7ff10e3b..fa189c472 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" @@ -488,3 +489,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 4935469b5..2f25ee591 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)