Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datadog_monitor_json] Fix erroneous drift on restriction_policy field #2767

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion datadog/resource_datadog_monitor_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,18 @@ 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)
queryAttrs := make([]string, 0)
if _, ok := attrMap["restricted_roles"]; !ok {
url += "?with_restricted_roles=false"
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in addition to concern Phillip raised, couple of things to consider here

  • if restricted_roles exist, we should not return restriction policy and vice versa
  • we perform sorting on the restriction policy value that is returned, so you would have to take that into consideration as that may not be the same order in which the user defined restriction policy in their terraform file

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)
Expand Down
Loading