Skip to content

Commit d64b7c8

Browse files
authored
feat(resource): Processor Bundles (#140)
* AnyResourceV1 support processors * processor bundles * add larger test * Revert test change * Add test case * lint
1 parent bac0e7e commit d64b7c8

File tree

13 files changed

+735
-15
lines changed

13 files changed

+735
-15
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
subcategory: "Pipeline"
3+
description: |-
4+
A Processor Bundle creates a BindPlane OP processor bundle that can be attached
5+
to a Configuration's sources or destinations.
6+
---
7+
8+
# bindplane_processor
9+
10+
The `bindplane_processor_bundle` resource creates a [BindPlane Processor Bundle](https://bindplane.com/docs/feature-guides/processor-bundles)
11+
The processor bundle can be used by multiple [configurations](./bindplane_configuration.md).
12+
13+
## Options
14+
15+
| Option | Type | Default | Description |
16+
| ------------------- | ----- | -------- | ---------------------------- |
17+
| `name` | string | required | The processor name. |
18+
| `processor` | processor block | required | One or more processor blocks. |
19+
| `rollout` | bool | required | Whether or not updates to the processor should trigger an automatic rollout of any configuration that uses it. |
20+
21+
Processor block supports the following:
22+
23+
| Option | Type | Default | Description |
24+
| ------------------ | ----- | -------- | ---------------------------- |
25+
| `name` | string | required | The name of the processor to include in the bundle. |
26+
27+
## Usage
28+
29+
This example shows how to combine the batch and json processors
30+
into a processor bundle.
31+
32+
```hcl
33+
resource "bindplane_processor" "json-parse-body" {
34+
rollout = false
35+
name = "json-parse-body"
36+
type = "parse_json"
37+
parameters_json = jsonencode(
38+
[
39+
{
40+
"name": "telemetry_types",
41+
"value": [
42+
"Logs",
43+
]
44+
},
45+
{
46+
"name": "log_source_field_type",
47+
"value": "Body"
48+
},
49+
{
50+
"name": "log_body_source_field",
51+
"value": ""
52+
},
53+
{
54+
"name": "log_target_field_type",
55+
"value": "Body"
56+
}
57+
]
58+
)
59+
}
60+
61+
resource "bindplane_processor" "batch" {
62+
rollout = false
63+
name = "example-batch"
64+
type = "batch"
65+
}
66+
67+
resource "bindplane_processor_bundle" "bundle" {
68+
rollout = true
69+
name = "my-bundle"
70+
71+
processor {
72+
name = bindplane_processor.json-parse-body.name
73+
}
74+
75+
processor {
76+
name = bindplane_processor.batch.name
77+
}
78+
}
79+
```
80+
81+
After applying the configuration with `terraform apply`, you can view the processor bundle with
82+
the `bindplane get processor "my-bundle"` command.
83+
84+
```bash
85+
NAME TYPE
86+
my-bundle processor_bundle:1
87+
```
88+
```yaml
89+
# bindplane get processor my-bundle -o yaml
90+
apiVersion: bindplane.observiq.com/v1
91+
kind: Processor
92+
metadata:
93+
id: 01JKEX6ZZNHHNX171N8JKQC57M
94+
name: my-bundle
95+
hash: 5ee0be3c33158b0452bf77da9413c4a571c2b9c407a2b84481741067c7c962b8
96+
version: 1
97+
dateModified: 2025-02-06T19:33:33.191627322-05:00
98+
spec:
99+
type: processor_bundle:1
100+
processors:
101+
- id: p-example-batch
102+
name: example-batch:1
103+
- id: p-json-parse-body
104+
name: json-parse-body:1
105+
status:
106+
latest: true
107+
```
108+
109+
## Import
110+
111+
When using the [terraform import command](https://developer.hashicorp.com/terraform/cli/commands/import),
112+
processor bundles can be imported. For example:
113+
114+
```bash
115+
terraform import bindplane_processor_bundle.bundle {{name}}
116+
```

example/processor_bundle.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "bindplane_processor_bundle" "bundle" {
2+
rollout = true
3+
name = "my-bundle"
4+
5+
processor {
6+
name = bindplane_processor.custom.name
7+
}
8+
9+
processor {
10+
name = bindplane_processor.batch.name
11+
}
12+
}

internal/resource/resource.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,23 @@ import (
2323
)
2424

2525
// AnyResourceV1 takes a BindPlane resource name, kind, type, parameters
26-
// and returns a bindplane.observiq.com/v1.AnyResource. Supported resources
27-
// are Sources, Destinations, and Processors. For configurations, use
28-
// AnyResourceFromConfigurationV1.
29-
func AnyResourceV1(rName, rType string, rKind model.Kind, rParameters []model.Parameter) (model.AnyResource, error) {
26+
// and processors and returns a bindplane.observiq.com/v1.AnyResource.
27+
// Supported resources are Sources, Destinations, and Processors. For
28+
// configurations, use AnyResourceFromConfigurationV1.
29+
//
30+
// rParameters and rProcessors can be nil.
31+
func AnyResourceV1(rName, rType string, rKind model.Kind, rParameters []model.Parameter, rProcessors []model.ResourceConfiguration) (model.AnyResource, error) {
32+
procs := []map[string]string{}
33+
for _, p := range rProcessors {
34+
proc := map[string]string{}
35+
36+
if p.Name != "" {
37+
proc["name"] = p.Name
38+
}
39+
40+
procs = append(procs, proc)
41+
}
42+
3043
switch rKind {
3144
case model.KindSource, model.KindDestination, model.KindProcessor, model.KindExtension:
3245
return model.AnyResource{
@@ -40,6 +53,7 @@ func AnyResourceV1(rName, rType string, rKind model.Kind, rParameters []model.Pa
4053
Spec: map[string]any{
4154
"type": rType,
4255
"parameters": rParameters,
56+
"processors": procs,
4357
},
4458
}, nil
4559
default:

internal/resource/resource_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestAnyResourceV1(t *testing.T) {
2828
rType string
2929
rkind model.Kind
3030
rParameters []model.Parameter
31+
rProcessors []model.ResourceConfiguration
3132
expectErr string
3233
}{
3334
{
@@ -45,6 +46,7 @@ func TestAnyResourceV1(t *testing.T) {
4546
Value: []string{"test"},
4647
},
4748
},
49+
nil,
4850
"",
4951
},
5052
{
@@ -58,6 +60,7 @@ func TestAnyResourceV1(t *testing.T) {
5860
Value: "my-project",
5961
},
6062
},
63+
nil,
6164
"",
6265
},
6366
{
@@ -66,6 +69,7 @@ func TestAnyResourceV1(t *testing.T) {
6669
"filter",
6770
model.KindProcessor,
6871
nil,
72+
nil,
6973
"",
7074
},
7175
{
@@ -74,6 +78,7 @@ func TestAnyResourceV1(t *testing.T) {
7478
"pprof",
7579
model.KindExtension,
7680
nil,
81+
nil,
7782
"",
7883
},
7984
{
@@ -82,13 +87,30 @@ func TestAnyResourceV1(t *testing.T) {
8287
"resource",
8388
model.KindAgent,
8489
nil,
90+
nil,
8591
"unknown bindplane resource kind: Agent",
8692
},
93+
{
94+
"valid-processors",
95+
"my-bundle",
96+
"bundle",
97+
model.KindProcessor,
98+
nil,
99+
[]model.ResourceConfiguration{
100+
{
101+
Name: "filter-a",
102+
},
103+
{
104+
Name: "filter-b",
105+
},
106+
},
107+
"",
108+
},
87109
}
88110

89111
for _, tc := range cases {
90112
t.Run(tc.name, func(t *testing.T) {
91-
_, err := AnyResourceV1(tc.rName, tc.rType, tc.rkind, tc.rParameters)
113+
_, err := AnyResourceV1(tc.rName, tc.rType, tc.rkind, tc.rParameters, tc.rProcessors)
92114
if tc.expectErr != "" {
93115
require.Error(t, err)
94116
require.ErrorContains(t, err, tc.expectErr)

provider/provider.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ func Configure() *schema.Provider {
114114
},
115115
},
116116
ResourcesMap: map[string]*schema.Resource{
117-
"bindplane_configuration": resourceConfiguration(),
118-
"bindplane_destination": resourceDestination(),
119-
"bindplane_source": resourceSource(), // TODO(jsirianni): Determine if sources should be supported.
120-
"bindplane_processor": resourceProcessor(),
121-
"bindplane_extension": resourceExtension(),
117+
"bindplane_configuration": resourceConfiguration(),
118+
"bindplane_destination": resourceDestination(),
119+
"bindplane_source": resourceSource(),
120+
"bindplane_processor": resourceProcessor(),
121+
"bindplane_processor_bundle": resourceProcessorBundle(),
122+
"bindplane_extension": resourceExtension(),
122123
},
123124
}
124125
}

provider/resource_destination.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func resourceDestinationCreate(d *schema.ResourceData, meta any) error {
9898
parameters = params
9999
}
100100

101-
r, err := resource.AnyResourceV1(name, destType, model.KindDestination, parameters)
101+
r, err := resource.AnyResourceV1(name, destType, model.KindDestination, parameters, nil)
102102
if err != nil {
103103
return err
104104
}

provider/resource_extension.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func resourceExtensionCreate(d *schema.ResourceData, meta any) error {
9898
parameters = params
9999
}
100100

101-
r, err := resource.AnyResourceV1(name, extensionType, model.KindExtension, parameters)
101+
r, err := resource.AnyResourceV1(name, extensionType, model.KindExtension, parameters, nil)
102102
if err != nil {
103103
return err
104104
}

provider/resource_processor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func resourceProcessor() *schema.Resource {
4646
Type: schema.TypeString,
4747
Required: true,
4848
ForceNew: false,
49-
Description: "The destination type to use for processor creation.",
49+
Description: "The processor type to use for processor creation.",
5050
},
5151
"parameters_json": {
5252
Type: schema.TypeString,
@@ -98,7 +98,7 @@ func resourceProcessorCreate(d *schema.ResourceData, meta any) error {
9898
parameters = params
9999
}
100100

101-
r, err := resource.AnyResourceV1(name, processorType, model.KindProcessor, parameters)
101+
r, err := resource.AnyResourceV1(name, processorType, model.KindProcessor, parameters, nil)
102102
if err != nil {
103103
return err
104104
}

0 commit comments

Comments
 (0)