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

fix(entity): add argument ignore_not_found to ignore "not found" errors #2628

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading