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

Feature Request: Data Source for newrelic_synthetics_script_monitor #2750

Closed
dribblor opened this issue Oct 3, 2024 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@dribblor
Copy link

dribblor commented Oct 3, 2024

Feature Description

Add terraform data source for synthetic scripts (newrelic_synthetics_script_monitor)

Describe Alternatives

None

Additional context

It would be useful to be able to retrieve data for synthetic scripts, such as it's GUID, for use when creating service levels (newrelic_service_level) and entity tags (newrelic_entity_tags) which require entity GUID.

@pranav-new-relic
Copy link
Member

Hi @dribblor, is your request specific to Script Monitors? If I understand this right, does your request ask for an inclusion of a data source that can "fetch" (all kinds of) Synthetic Monitors when searched with their name, so the GUID, script, etc. of such monitors can be retrieved and used with other resources?

@pranav-new-relic pranav-new-relic added the enhancement New feature or request label Oct 8, 2024
@pranav-new-relic pranav-new-relic changed the title Data source for newrelic_synthetics_script_monitor Feature Request: Data Source for newrelic_synthetics_script_monitor Oct 8, 2024
@dribblor
Copy link
Author

dribblor commented Oct 8, 2024

@pranav-new-relic My request was specific to Script Monitors. I can't remember now what the use case was because I ended up working around it, but at the time things would have been much simpler if I could just use a data source to fetch the GUID's of some synthetic script monitors.

I'm not requesting data sources for other types of monitor, but I'm not saying you shouldn't do that either.

@pranav-new-relic
Copy link
Member

okay, thanks for sharing this info. While we wouldn't be able to get to this soon owing to other priority items, this certainly is a usecase we shall consider sometime. Did you want to simply search for a monitor with its name via the data source and fetch its GUID and other attributes, or also filter it with other attributes? Just trying to gather ideas so we think about these when we get to do this in future, if we do :) thanks!

@dribblor
Copy link
Author

dribblor commented Oct 8, 2024

Searching for a monitor by it's name is perfectly fine for me, thanks. And no rush :)

@pranav-new-relic
Copy link
Member

Hey @dribblor, sorry, we weren't able to get to this owing to a heap of other priorities; however, I think we do not need to have a new data source to fit this usecase; instead, we can leverage the newrelic_entity data source (since the data source does return entity tags and the GUID of the entity, which are the two things you seem to need).

I've shared a sample configuration of what would be needed to get these attributes of a Synthetics Scripted monitor, by searching with its name.

data "newrelic_entity" "foo" {
  name   = "some-synthetics-scripted-monitor"
  domain = "SYNTH"
  type   = "MONITOR"
}

locals {
  key_value_map = { for pair in jsondecode(data.newrelic_entity.foo.entity_tags) : pair.key => pair.values }
}

output "script_monitor_guid" {
  value = data.newrelic_entity.foo.guid
}

output "script_monitor_entity_tags" {
  value = local.key_value_map
}

You'll see by the end of this (upon a terraform apply) that script_monitor_guid and script_monitor_entity_tags would get you the GUID and tags of the monitor respectively.

You can also use the following block (additionally) to "check" via Terraform if the monitor returned actually is a Scripted Monitor - this is a relatively new feature in Terraform that might be useful for a check, so wanted to share this. However, the above block should get you what you need.

check "monitor_type_exists_check" {
  assert {
    condition     = contains(keys(local.key_value_map), "monitorType")
    error_message = "The monitorType tag does not exist in key_value_map."
  }
}

check "monitor_type_check" {
  assert {
    condition     = startswith(local.key_value_map["monitorType"][0], "Script")
    error_message = "The monitorType does not start with 'Script', indicating that this might not be a Synthetics Scripted Monitor."
  }
}

Since our team opines the newrelic_entity data source would suffice this usecase; we shall be closing this issue. Thank you for reporting, and please let us know if you think there could still be a need for a dedicated data source for scripted synthetic monitors, the desired behaviour of which is not matched by the current newrelic_entity data source.

@pranav-new-relic pranav-new-relic closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants