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

newrelic_entity_tags right after creating a resource #756

Closed
trunet opened this issue Jul 8, 2020 · 28 comments
Closed

newrelic_entity_tags right after creating a resource #756

trunet opened this issue Jul 8, 2020 · 28 comments

Comments

@trunet
Copy link

trunet commented Jul 8, 2020

Feature Description

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.

Describe Alternatives

Using depends_on on the data (that is not recommended on terraform documentation) and it will fail once and succeed on second run.

Additional context

From https://discuss.newrelic.com/t/synthetic-labels-end-of-life-for-tf-new-relic-provider/104468/6

I’m 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)
    }
  }
}
@ctrombley
Copy link
Contributor

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.

@trunet
Copy link
Author

trunet commented Jul 10, 2020

@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)
    }
  }
}

@trunet
Copy link
Author

trunet commented Jul 10, 2020

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.

@trunet
Copy link
Author

trunet commented Jul 29, 2020

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

@trunet
Copy link
Author

trunet commented Jul 29, 2020

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"
}

@MAN98
Copy link

MAN98 commented Sep 2, 2020

@ctrombley - Is there updates on when NerdGraph GraphQL APIs will be available to fix this issue? Thanks for your reply.

@zlesnr
Copy link
Contributor

zlesnr commented Sep 21, 2020

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.

@MAN98
Copy link

MAN98 commented Sep 22, 2020

@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

@stale
Copy link

stale bot commented Oct 6, 2020

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.

@stale stale bot added the stale label Oct 6, 2020
@stale stale bot removed the stale label Oct 6, 2020
@stale
Copy link

stale bot commented Oct 20, 2020

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.

@stale stale bot added the stale label Oct 20, 2020
@stale
Copy link

stale bot commented Oct 28, 2020

This issue has been automatically closed due to a lack of activity for an extended period of time.

@stale stale bot closed this as completed Oct 28, 2020
@MAN98
Copy link

MAN98 commented Oct 28, 2020

This is definitely still an issue and should not be closed.

@zlesnr zlesnr reopened this Oct 28, 2020
@stale stale bot removed the stale label Oct 28, 2020
@zlesnr zlesnr added the pinned label Oct 28, 2020
@zlesnr
Copy link
Contributor

zlesnr commented Oct 30, 2020

I'm hearing that the synthetics resources may be available in Nerdgraph soon.

@MAN98
Copy link

MAN98 commented Oct 30, 2020

That's great news @zlesnr. Please do keep us updated.

@imsathyakumar
Copy link

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

image

@zlesnr
Copy link
Contributor

zlesnr commented Nov 12, 2020

That looks like a new issue to me @imsathyakumar. If so, please file a new issue.

@joshuaakelly
Copy link

joshuaakelly commented Sep 24, 2021

Just a note for anyone that's trying to implement this with for_each looped resource definitions. I found that even using @trunet's workaround with the time_sleep dependency I was still getting the error:

Error: the name '[REDACTED]' does not match any New Relic One entity for the given search parameters (ignore_case: false)

Works on first run but succeeds on subsequent runs. It look like the time_sleep dependency was not working properly, at least not for all resources in the loop. The following configuration seems to work:

data "newrelic_entity" "synthetic_loop" {

  for_each = {
    for synthetic in local.synthetic:
    synthetic.name => synthetic
  }

  name = time_sleep.wait_10_seconds_synthetic[each.value.name].triggers["name"]
  
  domain = "SYNTH"
  type = "MONITOR"

}

resource "time_sleep" "wait_10_seconds_synthetic" {

  for_each = {
    for synthetic in local.synthetic:
    synthetic.name => synthetic
  }
  
  create_duration = "10s"
  
  triggers = {
    name = newrelic_synthetics_monitor.synthetic_loop[each.value.name].name
  }

}

resource "newrelic_synthetics_monitor" "synthetic_loop" {

  for_each = {
    for synthetic in local.synthetic:
    synthetic.name => synthetic
  }

  name      = join(" ", [local.tags.policy_name, each.value.name])
  type      = each.value.type
  frequency = each.value.frequency
  status    = each.value.enabled ? "ENABLED": "DISABLED"
  locations = each.value.location
  uri       = each.value.uri

}

resource "newrelic_entity_tags" "synthetic_loop" {

    for_each = {
    for synthetic in local.synthetic:
    synthetic.name => synthetic
  }

  guid = data.newrelic_entity.synthetic_loop[each.value.name].guid

  dynamic "tag" {
    for_each = local.tags
    content {
      key = tag.key
      values = [tag.value]
    }
  }

}

The changes being:

  • Using implicit dependencies via the triggers attribute instead of the depends_on attribute to establish the relationship between the newrelic_entity and time_sleep resources
  • Looping the time_sleep resource so that there is one for each synthetic monitor. Note that they appear to run in parallel so this does not add an unwanted additional delay.

@MAN98
Copy link

MAN98 commented Nov 16, 2021

Is there any timeline when would this be resolved?

@kidk
Copy link
Contributor

kidk commented Nov 17, 2021

The new API's for synthetics should be available soon, and will plan in the work to migrate synthetics resources to the new API. No timeline at the moment.

@arhill05
Copy link

Just adding another voice of support for this issue - we ran into this exact same problem today.

@burck1
Copy link
Contributor

burck1 commented Mar 29, 2022

I would also like to vote for this issue. We ran into this same problem today.

@nikonovak
Copy link

Running into same issue :(

@lizgene
Copy link

lizgene commented Apr 12, 2022

Just to add another voice to the queue to keep this active - our team is also looking for a way to manage tags on synthetics and plan on waiting for this fix before we do.

@kidk
Copy link
Contributor

kidk commented Apr 25, 2022

Update from the team: We are currently in the process of migrating Synthetics to the new API's. So you can soon expect a better solution than sleep 😅 Thanks everyone for your patience.

@zeffron
Copy link
Contributor

zeffron commented Apr 25, 2022

Update from the team: We are currently in the process of migrating Synthetics to the new API's. So you can soon expect a better solution than sleep 😅 Thanks everyone for your patience.

That was the update from November 2021. Is there an ETA of when we can expect this migration to be complete?

@kidk
Copy link
Contributor

kidk commented Apr 26, 2022

The update was indeed similar, at that time the new API was not yet available, now it is. We hope to have this all done before the summer.

@kidk kidk added this to the Synthetics GraphQL milestone May 31, 2022
@dconnolly-sfdc
Copy link

+1 for this issue
hoping for a solution soon

@kidk
Copy link
Contributor

kidk commented Aug 29, 2022

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 new resources now include a tags attribute which will allow you to set the right tags from the resource without the need for newrelic_entity_tags. The monitor now also returns the GUID (id attribute) which should help with use of newrelic_entity_tags.

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.

@kidk kidk closed this as completed Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests