Skip to content

Commit

Permalink
fix(newrelic_entity): add argument ignore_not_found to ignore "not …
Browse files Browse the repository at this point in the history
…found" errors (#2628)
  • Loading branch information
pranav-new-relic authored Mar 28, 2024
1 parent e6a5d8e commit 5d87ded
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions newrelic/data_source_newrelic_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func dataSourceNewRelicEntity() *schema.Resource {
return strings.EqualFold(old, new) // Case fold this attribute when diffing
},
},
"ignore_not_found": {
Type: schema.TypeBool,
Default: false,
Optional: true,
Description: "A boolean attribute which when set to true, does not throw an error if the queried entity is not found.",
},
"tag": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -144,7 +150,21 @@ func dataSourceNewRelicEntityRead(ctx context.Context, d *schema.ResourceData, m
}

if entity == nil {
if d.Get("ignore_not_found").(bool) {
log.Printf("[INFO] Entity not found, ignoring error")
d.SetId("")
var diags diag.Diagnostics
diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "no entities found for the provided search parameters, please ensure your schema attributes are valid.\n" +
"This message is being displayed as a warning and not as an error as `ignore_not_found` has been set to true.\n" +
"Ignoring the 'not found' error can lead to downstream errors if the values of attributes exported by this\n" +
"data source are used elsewhere, since all of these values would be null. Please use this attribute at your own risk.\n",
})
return diags
}
return diag.FromErr(fmt.Errorf("no entities found for the provided search parameters, please ensure your schema attributes are valid"))

}

return diag.FromErr(flattenEntityData(entity, d))
Expand Down
3 changes: 3 additions & 0 deletions website/docs/d/entity.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ The following arguments are supported:
* `type` - (Optional) The entity's type. Valid values are APPLICATION, DASHBOARD, HOST, MONITOR, WORKLOAD, AWSLAMBDAFUNCTION, SERVICE_LEVEL, and KEY_TRANSACTION. Note: Other entity types may also be queryable as the list of entity types may fluctuate over time.
* `domain` - (Optional) The entity's domain. Valid values are APM, BROWSER, INFRA, MOBILE, SYNTH, and EXT. If not specified, all domains are searched.
* `tag` - (Optional) A tag applied to the entity. See [Nested tag blocks](#nested-`tag`-blocks) below for details.
* `ignore_not_found`- (Optional) A boolean argument that, when set to true, prevents an error from being thrown when the queried entity is not found. Instead, a warning is displayed. Defaults to `false`.

-> **WARNING:** Setting the `ignore_not_found` argument to `true` will display an 'entity not found' warning instead of throwing an error. This can lead to downstream errors if the values of attributes exported by this data source are used elsewhere, as all of these values would be null. Please use this argument at your own risk.

### Nested `tag` blocks

Expand Down

0 comments on commit 5d87ded

Please sign in to comment.