To be able to use newrelic_entity_tags, we need to have the entity GUID. However, the resource is not yet created when data is acquired. We need to have a way to get GUID and/or resource name from the resource itself so data will auto depend on it during apply.
Using depends_on on the data (that is not recommended on terraform documentation) and it will fail once and succeed on second run.
From https://discuss.newrelic.com/t/synthetic-labels-end-of-life-for-tf-new-relic-provider/104468/6
I鈥檓 having problems adding tags to a newrelic_synthetics_monitor.
The example below returns an error because during refresh phase, data is not available because newrelic_synthetics_monitor is not created yet.
If I add a depends_on to data, it will fail on first run, and run successfully on second.
How do I manage to have this running successfully in one run? Is it possible to implement on newrelic_synthetics_monitor to return its entity GUID in addition to ID?
resource "newrelic_synthetics_monitor" "ssl" {
name = var.name
type = "SCRIPT_API"
frequency = var.frequency
status = var.status
locations = var.locations
sla_threshold = var.sla_threshold
}
data "newrelic_entity" "ssl" {
name = var.name
type = "MONITOR"
domain = "SYNTH"
}
resource "newrelic_entity_tags" "ssl" {
guid = data.newrelic_entity.ssl.guid
dynamic "tag" {
for_each = merge(var.tags, local.common_tags)
content {
key = tag.key
values = list(tag.value)
}
}
}
Hi @trunet !
We are in the middle of a large transition that involves moving most of our resources from legacy REST-based APIs to the NerdGraph GraphQL API. Synthetics is a domain that has not been moved yet, and for this reason we can't surface entity GUIDs directly after the monitor's creation. Once synthetic monitors surface in NerdGraph, we should be able to do exactly that.
In the meantime, I wonder if the backend just needs a few seconds to index the new resource. Can you try adding a 10-30s sleep after monitor creation and see if the helps?
https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep
I know this is not ideal but it should be able to get you moving until Synthetics is moved into NerdGraph.
@ctrombley this workaround works fine. I added a 10s sleep in between and it works flawless.
For future reference if anyone face this problem:
resource "newrelic_synthetics_monitor" "ssl" {
name = var.name
type = "SCRIPT_API"
frequency = var.frequency
status = var.status
locations = var.locations
sla_threshold = var.sla_threshold
}
resource "time_sleep" "wait_10_seconds" {
depends_on = [newrelic_synthetics_monitor.ssl]
create_duration = "10s"
}
data "newrelic_entity" "ssl" {
name = var.name
domain = "SYNTH"
depends_on = [time_sleep.wait_10_seconds]
}
resource "newrelic_entity_tags" "ssl" {
guid = data.newrelic_entity.ssl.guid
dynamic "tag" {
for_each = merge(var.tags, local.common_tags)
content {
key = tag.key
values = list(tag.value)
}
}
}
I'm still having issues. The sleep 10 is not enough, and in my case, I got some synthetics that took 15 minutes to be able to have a GUID available.
There's another problem, not sure if you want another ticket for this. If the data name is a constant (in my case var.name), it will ALWAYS try to get on refresh phase and trigger an error if you try to rename one monitor. If newrelic_synthetics_monitor had a name attribute exported, than it would depends and would work I guess.
resource "newrelic_synthetics_monitor" "[REDACTED]_endtoend" {
name = var.name
type = "SCRIPT_BROWSER"
frequency = var.frequency
status = var.status
locations = var.locations
sla_threshold = var.sla_threshold
}
resource "time_sleep" "wait_10_seconds" {
depends_on = [newrelic_synthetics_monitor.reaxys_endtoend]
create_duration = "10s"
}
data "newrelic_entity" "[REDACTED]_endtoend" {
name = var.name
type = "MONITOR"
domain = "SYNTH"
depends_on = [time_sleep.wait_10_seconds, newrelic_synthetics_monitor.reaxys_endtoend]
}
Error:
Error: the name '[REDACTED]' does not match any New Relic One entity for the given search parameters
I manage to workaround this (once again), doing this:
data "null_data_source" "name" {
inputs = {
name = var.name
}
depends_on = [time_sleep.wait_10_seconds]
}
data "newrelic_entity" "[REDACTED]_endtoend" {
name = data.null_data_source.name
type = "MONITOR"
domain = "SYNTH"
}
@ctrombley - Is there updates on when NerdGraph GraphQL APIs will be available to fix this issue? Thanks for your reply.
Is this still an issue with the latest release? I can't tell if this was the same issue as the service-defined tags, or slightly different.
@zlesnr - This is still an issue since this was related to the fact that the newrelic_synthetics_monitor resource does not output an entity_guid after create. I think that's because the APIs for synthetics are still not in NERDGraph.
Note: I did try using the latest provider version creating a new synthetic and assign a tag right away and still same error as above
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs.
This issue has been automatically closed due to a lack of activity for an extended period of time.
This is definitely still an issue and should not be closed.
I'm hearing that the synthetics resources may be available in Nerdgraph soon.
That's great news @zlesnr. Please do keep us updated.
Now using the data component looking for guid is creating a chaos in terraform plan. Plan is reporting a change for all our Synthetics, with the message "# module.[monitor_name].data.newrelic_entity.browser will be read during apply". It is getting very difficult to look for the actual change due to these false messages. These data bugs are reported in AWS terraform providers too and they got it fixed. Check here

That looks like a new issue to me @imsathyakumar. If so, please file a new issue.
Most helpful comment
This is definitely still an issue and should not be closed.