generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for filter processor. Ref: LOG-18377
- Loading branch information
1 parent
e66182e
commit 6dd2675
Showing
8 changed files
with
654 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "mezmo_filter_processor Resource - terraform-provider-mezmo" | ||
subcategory: "" | ||
description: |- | ||
Define condition(s) to include or exclude events from the pipeline | ||
--- | ||
|
||
# mezmo_filter_processor (Resource) | ||
|
||
Define condition(s) to include or exclude events from the pipeline | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `action` (String) How to handle events matching this criteria | ||
- `conditional` (Attributes) A group of expressions (optionally nested) joined by a logical operator (see [below for nested schema](#nestedatt--conditional)) | ||
- `pipeline_id` (String) The uuid of the pipeline | ||
|
||
### Optional | ||
|
||
- `description` (String) A user-defined value describing the processor | ||
- `inputs` (List of String) The ids of the input components | ||
- `title` (String) A user-defined title for the processor | ||
|
||
### Read-Only | ||
|
||
- `generation_id` (Number) An internal field used for component versioning | ||
- `id` (String) The uuid of the processor | ||
|
||
<a id="nestedatt--conditional"></a> | ||
### Nested Schema for `conditional` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions)) | ||
- `expressions_group` (Attributes List) A group of expressions joined by a logical operator (see [below for nested schema](#nestedatt--conditional--expressions_group)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions"></a> | ||
### Nested Schema for `conditional.expressions` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string | ||
|
||
|
||
<a id="nestedatt--conditional--expressions_group"></a> | ||
### Nested Schema for `conditional.expressions_group` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions)) | ||
- `expressions_group` (Attributes List) A group of expressions joined by a logical operator (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions_group--expressions"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string | ||
|
||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--expressions)) | ||
- `expressions_group` (Attributes List) A group of expressions joined by a logical operator (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--expressions_group)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--expressions"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string | ||
|
||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--expressions_group"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions)) | ||
- `expressions_group` (Attributes List) A group of expressions joined by a logical operator (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string | ||
|
||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions_group` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--expressions)) | ||
- `expressions_group` (Attributes List) A group of expressions joined by a logical operator (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--expressions_group)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--expressions"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions_group.logical_operation` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string | ||
|
||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--expressions_group"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions_group.logical_operation` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--logical_operation--expressions)) | ||
- `expressions_group` (Attributes List) A group of expressions joined by a logical operator (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--logical_operation--expressions_group)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--logical_operation--expressions"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions_group.logical_operation.logical_operation` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string | ||
|
||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--logical_operation--expressions_group"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions_group.logical_operation.logical_operation` | ||
|
||
Optional: | ||
|
||
- `expressions` (Attributes List) Defines a list of expressions for field comparisons (see [below for nested schema](#nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--logical_operation--logical_operation--expressions)) | ||
- `logical_operation` (String) The logical operation (AND/OR) to be applied to the list of conditionals | ||
|
||
<a id="nestedatt--conditional--expressions_group--expressions_group--logical_operation--expressions_group--logical_operation--logical_operation--expressions"></a> | ||
### Nested Schema for `conditional.expressions_group.expressions_group.logical_operation.expressions_group.logical_operation.logical_operation.logical_operation` | ||
|
||
Required: | ||
|
||
- `field` (String) The field path whose value will be used in the comparison | ||
- `operator` (String) The comparison operator | ||
|
||
Optional: | ||
|
||
- `value_number` (Number) The operand to compare the field value with, when the value is a number | ||
- `value_string` (String) The operand to compare the field value with, when the value is a string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
terraform { | ||
required_providers { | ||
mezmo = { | ||
source = "registry.terraform.io/mezmo/mezmo" | ||
} | ||
} | ||
required_version = ">= 1.1.0" | ||
} | ||
|
||
provider "mezmo" { | ||
auth_key = "my secret" | ||
} | ||
|
||
resource "mezmo_pipeline" "pipeline1" { | ||
title = "My pipeline" | ||
} | ||
|
||
resource "mezmo_demo_source" "source1" { | ||
pipeline_id = mezmo_pipeline.pipeline1.id | ||
title = "My source" | ||
format = "apache_common" | ||
} | ||
|
||
resource "mezmo_filter_processor" "processor1" { | ||
pipeline_id = mezmo_pipeline.pipeline1.id | ||
title = "My processor" | ||
description = "This processor filters logs" | ||
inputs = [mezmo_demo_source.source1.id] | ||
conditionals = { | ||
expressions = [ | ||
{ | ||
field = ".status" | ||
operator = "greater_or_equal" | ||
value_number = 300 | ||
}, | ||
{ | ||
field = ".level" | ||
operator = "contains" | ||
value_string = "info" | ||
} | ||
] | ||
logical_operation = "OR" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package processors | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
|
||
. "github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
. "github.com/mezmo/terraform-provider-mezmo/internal/client" | ||
. "github.com/mezmo/terraform-provider-mezmo/internal/provider/models/modelutils" | ||
) | ||
|
||
const FILTER_PROCESSOR_NODE_NAME = "filter" | ||
const FILTER_PROCESSOR_TYPE_NAME = "filter" | ||
|
||
type FilterProcessorModel struct { | ||
Id StringValue `tfsdk:"id"` | ||
PipelineId StringValue `tfsdk:"pipeline_id"` | ||
Title StringValue `tfsdk:"title"` | ||
Description StringValue `tfsdk:"description"` | ||
Inputs ListValue `tfsdk:"inputs"` | ||
GenerationId Int64Value `tfsdk:"generation_id"` | ||
Action StringValue `tfsdk:"action" user_config:"true"` | ||
Conditional ObjectValue `tfsdk:"conditional" user_config:"true"` | ||
} | ||
|
||
var FilterProcessorResourceSchema = schema.Schema{ | ||
Description: "Define condition(s) to include or exclude events from the pipeline", | ||
Attributes: ExtendBaseAttributes(map[string]schema.Attribute{ | ||
"action": schema.StringAttribute{ | ||
Description: "How to handle events matching this criteria", | ||
Required: true, | ||
Validators: []validator.String{ | ||
stringvalidator.OneOf("allow", "drop"), | ||
}, | ||
}, | ||
"conditional": schema.SingleNestedAttribute{ | ||
Required: true, | ||
Description: ParentConditionalAttribute.Description, | ||
Attributes: ParentConditionalAttribute.Attributes, | ||
}, | ||
}), | ||
} | ||
|
||
func FilterProcessorFromModel(plan *FilterProcessorModel, previousState *FilterProcessorModel) (*Processor, diag.Diagnostics) { | ||
dd := diag.Diagnostics{} | ||
component := &Processor{ | ||
BaseNode: BaseNode{ | ||
Type: FILTER_PROCESSOR_NODE_NAME, | ||
Title: plan.Title.ValueString(), | ||
Description: plan.Description.ValueString(), | ||
UserConfig: map[string]any{ | ||
"action": plan.Action.ValueString(), | ||
}, | ||
}, | ||
} | ||
|
||
if previousState != nil { | ||
component.Id = previousState.Id.ValueString() | ||
component.GenerationId = previousState.GenerationId.ValueInt64() | ||
} | ||
|
||
component.Inputs = StringListValueToStringSlice(plan.Inputs) | ||
component.UserConfig["conditional"] = unwindConditionalFromModel(plan.Conditional) | ||
|
||
return component, dd | ||
} | ||
|
||
func FilterProcessorToModel(plan *FilterProcessorModel, component *Processor) { | ||
plan.Id = NewStringValue(component.Id) | ||
if component.Title != "" { | ||
plan.Title = NewStringValue(component.Title) | ||
} | ||
if component.Description != "" { | ||
plan.Description = NewStringValue(component.Description) | ||
} | ||
plan.GenerationId = NewInt64Value(component.GenerationId) | ||
plan.Inputs = SliceToStringListValue(component.Inputs) | ||
plan.Action = NewStringValue(component.UserConfig["action"].(string)) | ||
plan.Conditional = unwindConditionalToModel(component.UserConfig["conditional"].(map[string]any)) | ||
} |
Oops, something went wrong.