terraform-provider-newrelic
terraform-provider-newrelic copied to clipboard
How to create an SLO for Synthetic Check programmatically
The terraform module for a Service Level requires an entity GUID. The terraform module for a synthetic monitor currently does not export a GUID only an id. How is it best to be able to reference the GUID of the synthetic check object?
I see I can reference the GUID for a workload (exported by the terraform resource) and use this with the SLO (and then create my query statements appropriately). Is this the best way to solve the issue?
Hi @trustthewhiterabbit 👋 the Synthetics resources use our legacy REST API which doesn't use GUIDs. We're currently working on migrating the resources to the new GraphQL API which will return a GUID that you can use to create Service Levels.
@sandeepkumar-kagitha - Check if the below helps.
====================
variables.tf
variable "synthericslitarget" {}
variable "browser_monit_urls" {
type = map(object({
name = string
status = string
type = string
uri = string
}))
}
====================
terraform.tfvars
synthericslitarget = "99.5"
browser_monit_urls = {
NR-SYNTHETIC-MONIT-1 = {
name = "www.google.com"
status = "ENABLED"
type = "BROWSER" // Valid values are SIMPLE, BROWSER, SCRIPT_BROWSER, CERT_CHECK and SCRIPT_API
uri = "https://www.google.com"
},
NR-SYNTHETIC-MONIT-2 = {
name = "www.github.com"
status = "ENABLED"
type = "BROWSER" // Valid values are SIMPLE, BROWSER, SCRIPT_BROWSER, CERT_CHECK and SCRIPT_API
uri = "https://www.github.com"
}
}
=====================
syntheticssli.tf
// Use data source ( to pull the syntheric monitors with for_each
data "newrelic_entity" "syntheticsentity" {
for_each = var.browser_monit_urls
name = each.value["name"]
domain = "SYNTH"
type = "MONITOR"
}
// GUID is pulled from above data resources for every single syntheric URL.
resource "newrelic_service_level" "syntheticsli" {
for_each = data.newrelic_entity.syntheticsentity
guid = each.value.guid
name = "Success - ${tostring(each.value.name)}"
description = "Proportion of requests that are served faster than a threshold."
events {
account_id = var.maccount_id
valid_events {
from = "SyntheticCheck"
where = "monitorName = '${each.value["name"]}' AND result='SUCCESS'"
}
good_events {
from = "SyntheticCheck"
where = "monitorName = '${each.value["name"]}'"
}
}
objective {
target = var.synthericslitarget
time_window {
rolling {
count = 7
unit = "DAY"
}
}
}
}
@trustthewhiterabbit and @mayureshbhardwaj We've released V3 version of our provider which includes all of the new Synthetics features: https://registry.terraform.io/providers/newrelic/newrelic/latest/docs/guides/migration_guide_v3
The GUID is now available from the synthetics resources with the id
attribute.
Please let us know if you have any questions. If you encounter any issues please don't hesitate to create a new ticket.
I'll close this ticket as the work has been delivered. Feel free to continue the discussion if needed.