@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/observiq/bindplane-op-enterprise/model"
25
25
"github.com/observiq/terraform-provider-bindplane/client"
26
+ "github.com/observiq/terraform-provider-bindplane/internal/component"
26
27
"github.com/observiq/terraform-provider-bindplane/internal/configuration"
27
28
"github.com/observiq/terraform-provider-bindplane/internal/maputil"
28
29
"github.com/observiq/terraform-provider-bindplane/internal/resource"
@@ -101,19 +102,15 @@ func resourceConfigurationV2() *schema.Resource {
101
102
ForceNew : false ,
102
103
Elem : & schema.Resource {
103
104
Schema : map [string ]* schema.Schema {
104
- // TODO(jsirianni): Could be plural with
105
- // list or array. Provider would handle combining
106
- // them into string.
107
105
"telemetry_type" : {
108
106
Type : schema .TypeString ,
109
107
Required : true ,
110
108
ForceNew : false ,
111
- Description : "The telemetry type to route, such as 'logs', 'metrics', or 'traces'." ,
109
+ Description : "The telemetry type to route. Valid route types include 'logs', 'metrics', or 'traces' 'logs+metrics', 'logs+traces', 'metrics+traces', 'logs+metrics+ traces'." ,
112
110
ValidateFunc : func (val any , _ string ) (warns []string , errs []error ) {
113
- // Ensure one of logs, metrics, traces
114
111
telemetryType := val .(string )
115
- if telemetryType != "logs" && telemetryType != "metrics" && telemetryType != "traces" {
116
- errs = append (errs , errors . New ( "telemetry_type must be one of 'logs', 'metrics', or 'traces'" ) )
112
+ if err := component . ValidateRouteType ( telemetryType ); err != nil {
113
+ errs = append (errs , err )
117
114
}
118
115
return
119
116
},
@@ -124,6 +121,18 @@ func resourceConfigurationV2() *schema.Resource {
124
121
ForceNew : false ,
125
122
Elem : & schema.Schema {Type : schema .TypeString },
126
123
Description : "List of component names to route." ,
124
+ ValidateFunc : func (val any , _ string ) (warns []string , errs []error ) {
125
+ rawComponents := val .([]any )
126
+ components := []string {}
127
+ for _ , c := range rawComponents {
128
+ components = append (components , c .(string ))
129
+ }
130
+ validationErrors := component .ValidateRouteComponents (components )
131
+ if len (validationErrors ) > 0 {
132
+ errs = append (errs , validationErrors ... )
133
+ }
134
+ return
135
+ },
127
136
},
128
137
},
129
138
},
@@ -321,6 +330,22 @@ func resourceConfigurationV2Create(d *schema.ResourceData, meta any) error {
321
330
routes .Traces = append (routes .Traces , model.Route {
322
331
Components : components ,
323
332
})
333
+ case "logs+metrics" :
334
+ routes .LogsMetrics = append (routes .LogsMetrics , model.Route {
335
+ Components : components ,
336
+ })
337
+ case "logs+traces" :
338
+ routes .LogsTraces = append (routes .LogsTraces , model.Route {
339
+ Components : components ,
340
+ })
341
+ case "metrics+traces" :
342
+ routes .MetricsTraces = append (routes .MetricsTraces , model.Route {
343
+ Components : components ,
344
+ })
345
+ case "logs+metrics+traces" :
346
+ routes .LogsMetricsTraces = append (routes .LogsMetricsTraces , model.Route {
347
+ Components : components ,
348
+ })
324
349
}
325
350
}
326
351
}
0 commit comments