Skip to content

Commit

Permalink
feat(resource): Processor Bundles (#140)
Browse files Browse the repository at this point in the history
* AnyResourceV1 support processors

* processor bundles

* add larger test

* Revert test change

* Add test case

* lint
  • Loading branch information
jsirianni authored Feb 7, 2025
1 parent bac0e7e commit d64b7c8
Show file tree
Hide file tree
Showing 13 changed files with 735 additions and 15 deletions.
116 changes: 116 additions & 0 deletions docs/resources/bindplane_processor_bundles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
subcategory: "Pipeline"
description: |-
A Processor Bundle creates a BindPlane OP processor bundle that can be attached
to a Configuration's sources or destinations.
---

# bindplane_processor

The `bindplane_processor_bundle` resource creates a [BindPlane Processor Bundle](https://bindplane.com/docs/feature-guides/processor-bundles)
The processor bundle can be used by multiple [configurations](./bindplane_configuration.md).

## Options

| Option | Type | Default | Description |
| ------------------- | ----- | -------- | ---------------------------- |
| `name` | string | required | The processor name. |
| `processor` | processor block | required | One or more processor blocks. |
| `rollout` | bool | required | Whether or not updates to the processor should trigger an automatic rollout of any configuration that uses it. |

Processor block supports the following:

| Option | Type | Default | Description |
| ------------------ | ----- | -------- | ---------------------------- |
| `name` | string | required | The name of the processor to include in the bundle. |

## Usage

This example shows how to combine the batch and json processors
into a processor bundle.

```hcl
resource "bindplane_processor" "json-parse-body" {
rollout = false
name = "json-parse-body"
type = "parse_json"
parameters_json = jsonencode(
[
{
"name": "telemetry_types",
"value": [
"Logs",
]
},
{
"name": "log_source_field_type",
"value": "Body"
},
{
"name": "log_body_source_field",
"value": ""
},
{
"name": "log_target_field_type",
"value": "Body"
}
]
)
}
resource "bindplane_processor" "batch" {
rollout = false
name = "example-batch"
type = "batch"
}
resource "bindplane_processor_bundle" "bundle" {
rollout = true
name = "my-bundle"
processor {
name = bindplane_processor.json-parse-body.name
}
processor {
name = bindplane_processor.batch.name
}
}
```

After applying the configuration with `terraform apply`, you can view the processor bundle with
the `bindplane get processor "my-bundle"` command.

```bash
NAME TYPE
my-bundle processor_bundle:1
```
```yaml
# bindplane get processor my-bundle -o yaml
apiVersion: bindplane.observiq.com/v1
kind: Processor
metadata:
id: 01JKEX6ZZNHHNX171N8JKQC57M
name: my-bundle
hash: 5ee0be3c33158b0452bf77da9413c4a571c2b9c407a2b84481741067c7c962b8
version: 1
dateModified: 2025-02-06T19:33:33.191627322-05:00
spec:
type: processor_bundle:1
processors:
- id: p-example-batch
name: example-batch:1
- id: p-json-parse-body
name: json-parse-body:1
status:
latest: true
```
## Import
When using the [terraform import command](https://developer.hashicorp.com/terraform/cli/commands/import),
processor bundles can be imported. For example:
```bash
terraform import bindplane_processor_bundle.bundle {{name}}
```
12 changes: 12 additions & 0 deletions example/processor_bundle.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "bindplane_processor_bundle" "bundle" {
rollout = true
name = "my-bundle"

processor {
name = bindplane_processor.custom.name
}

processor {
name = bindplane_processor.batch.name
}
}
22 changes: 18 additions & 4 deletions internal/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,23 @@ import (
)

// AnyResourceV1 takes a BindPlane resource name, kind, type, parameters
// and returns a bindplane.observiq.com/v1.AnyResource. Supported resources
// are Sources, Destinations, and Processors. For configurations, use
// AnyResourceFromConfigurationV1.
func AnyResourceV1(rName, rType string, rKind model.Kind, rParameters []model.Parameter) (model.AnyResource, error) {
// and processors and returns a bindplane.observiq.com/v1.AnyResource.
// Supported resources are Sources, Destinations, and Processors. For
// configurations, use AnyResourceFromConfigurationV1.
//
// rParameters and rProcessors can be nil.
func AnyResourceV1(rName, rType string, rKind model.Kind, rParameters []model.Parameter, rProcessors []model.ResourceConfiguration) (model.AnyResource, error) {
procs := []map[string]string{}
for _, p := range rProcessors {
proc := map[string]string{}

if p.Name != "" {
proc["name"] = p.Name
}

procs = append(procs, proc)
}

switch rKind {
case model.KindSource, model.KindDestination, model.KindProcessor, model.KindExtension:
return model.AnyResource{
Expand All @@ -40,6 +53,7 @@ func AnyResourceV1(rName, rType string, rKind model.Kind, rParameters []model.Pa
Spec: map[string]any{
"type": rType,
"parameters": rParameters,
"processors": procs,
},
}, nil
default:
Expand Down
24 changes: 23 additions & 1 deletion internal/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAnyResourceV1(t *testing.T) {
rType string
rkind model.Kind
rParameters []model.Parameter
rProcessors []model.ResourceConfiguration
expectErr string
}{
{
Expand All @@ -45,6 +46,7 @@ func TestAnyResourceV1(t *testing.T) {
Value: []string{"test"},
},
},
nil,
"",
},
{
Expand All @@ -58,6 +60,7 @@ func TestAnyResourceV1(t *testing.T) {
Value: "my-project",
},
},
nil,
"",
},
{
Expand All @@ -66,6 +69,7 @@ func TestAnyResourceV1(t *testing.T) {
"filter",
model.KindProcessor,
nil,
nil,
"",
},
{
Expand All @@ -74,6 +78,7 @@ func TestAnyResourceV1(t *testing.T) {
"pprof",
model.KindExtension,
nil,
nil,
"",
},
{
Expand All @@ -82,13 +87,30 @@ func TestAnyResourceV1(t *testing.T) {
"resource",
model.KindAgent,
nil,
nil,
"unknown bindplane resource kind: Agent",
},
{
"valid-processors",
"my-bundle",
"bundle",
model.KindProcessor,
nil,
[]model.ResourceConfiguration{
{
Name: "filter-a",
},
{
Name: "filter-b",
},
},
"",
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, err := AnyResourceV1(tc.rName, tc.rType, tc.rkind, tc.rParameters)
_, err := AnyResourceV1(tc.rName, tc.rType, tc.rkind, tc.rParameters, tc.rProcessors)
if tc.expectErr != "" {
require.Error(t, err)
require.ErrorContains(t, err, tc.expectErr)
Expand Down
11 changes: 6 additions & 5 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func Configure() *schema.Provider {
},
},
ResourcesMap: map[string]*schema.Resource{
"bindplane_configuration": resourceConfiguration(),
"bindplane_destination": resourceDestination(),
"bindplane_source": resourceSource(), // TODO(jsirianni): Determine if sources should be supported.
"bindplane_processor": resourceProcessor(),
"bindplane_extension": resourceExtension(),
"bindplane_configuration": resourceConfiguration(),
"bindplane_destination": resourceDestination(),
"bindplane_source": resourceSource(),
"bindplane_processor": resourceProcessor(),
"bindplane_processor_bundle": resourceProcessorBundle(),
"bindplane_extension": resourceExtension(),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion provider/resource_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func resourceDestinationCreate(d *schema.ResourceData, meta any) error {
parameters = params
}

r, err := resource.AnyResourceV1(name, destType, model.KindDestination, parameters)
r, err := resource.AnyResourceV1(name, destType, model.KindDestination, parameters, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/resource_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func resourceExtensionCreate(d *schema.ResourceData, meta any) error {
parameters = params
}

r, err := resource.AnyResourceV1(name, extensionType, model.KindExtension, parameters)
r, err := resource.AnyResourceV1(name, extensionType, model.KindExtension, parameters, nil)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions provider/resource_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func resourceProcessor() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Description: "The destination type to use for processor creation.",
Description: "The processor type to use for processor creation.",
},
"parameters_json": {
Type: schema.TypeString,
Expand Down Expand Up @@ -98,7 +98,7 @@ func resourceProcessorCreate(d *schema.ResourceData, meta any) error {
parameters = params
}

r, err := resource.AnyResourceV1(name, processorType, model.KindProcessor, parameters)
r, err := resource.AnyResourceV1(name, processorType, model.KindProcessor, parameters, nil)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit d64b7c8

Please sign in to comment.