From df5c924d582f7a4b99dbc8af2b740a32b17d85b9 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Wed, 15 Jan 2025 16:43:43 +0100 Subject: [PATCH 1/2] [datadog_monitor_json] Fix erroneous drift on restriction_policy field --- datadog/resource_datadog_monitor_json.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/datadog/resource_datadog_monitor_json.go b/datadog/resource_datadog_monitor_json.go index 283e5915d0..50e6d36d2a 100644 --- a/datadog/resource_datadog_monitor_json.go +++ b/datadog/resource_datadog_monitor_json.go @@ -125,8 +125,15 @@ func resourceDatadogMonitorJSONRead(_ context.Context, d *schema.ResourceData, m // try to keep restricted_roles from mixing into it from API responses monitor := d.Get("monitor").(string) attrMap, _ := structure.ExpandJsonFromString(monitor) - if _, ok := attrMap["restricted_roles"]; !ok { - url += "?with_restricted_roles=false" + queryAttrs := make([]string, 0) + if _, ok := attrMap["restricted_roles"]; ok { + queryAttrs = append(queryAttrs, "with_restricted_roles=true") + } + if _, ok := attrMap["restriction_policy"]; ok { + queryAttrs = append(queryAttrs, "with_restriction_policy=true") + } + if len(queryAttrs) > 0 { + url = fmt.Sprintf("%s?%s", url, strings.Join(queryAttrs, "&")) } respByte, httpResp, err := utils.SendRequest(auth, apiInstances.HttpClient, "GET", url, nil) From 4985adb76e616c43b347267da44a53ad48105d32 Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Wed, 15 Jan 2025 16:49:44 +0100 Subject: [PATCH 2/2] Fix + Comment --- datadog/resource_datadog_monitor_json.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/datadog/resource_datadog_monitor_json.go b/datadog/resource_datadog_monitor_json.go index 50e6d36d2a..bd78b57ac5 100644 --- a/datadog/resource_datadog_monitor_json.go +++ b/datadog/resource_datadog_monitor_json.go @@ -126,9 +126,12 @@ func resourceDatadogMonitorJSONRead(_ context.Context, d *schema.ResourceData, m monitor := d.Get("monitor").(string) attrMap, _ := structure.ExpandJsonFromString(monitor) queryAttrs := make([]string, 0) - if _, ok := attrMap["restricted_roles"]; ok { - queryAttrs = append(queryAttrs, "with_restricted_roles=true") + if _, ok := attrMap["restricted_roles"]; !ok { + queryAttrs = append(queryAttrs, "with_restricted_roles=false") } + // Restriction policies are not returned in the API response by default + // In order to prevent some erroneous drift, we return it (and take in account in the state) + // if the user requests some restriction policy (behavior similar to Optional Computed) if _, ok := attrMap["restriction_policy"]; ok { queryAttrs = append(queryAttrs, "with_restriction_policy=true") }