Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions docs/resources/kibana_data_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ Optional:

Optional:

- `labeltemplate` (String)
- `pattern` (String)
- `urltemplate` (String)



Expand Down
27 changes: 23 additions & 4 deletions internal/kibana/data_view/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ func getSchema() schema.Schema {
"pattern": schema.StringAttribute{
Optional: true,
},
"urltemplate": schema.StringAttribute{
Optional: true,
},
"labeltemplate": schema.StringAttribute{
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -334,8 +340,15 @@ func dataViewFromResponse(resp data_views.DataViewResponseObjectDataView) apiDat

if params, ok := formatMap["params"]; ok {
if paramsMap, ok := params.(map[string]interface{}); ok {
fieldFormatParams := apiFieldFormatParams{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're never setting apiFormat.Params = &fieldFormatParams here and so the params are always nil (this is causing the current test failures).

if pattern, ok := paramsMap["pattern"]; ok {
apiFormat.Params = &apiFieldFormatParams{Pattern: pattern.(string)}
fieldFormatParams.Pattern = pattern.(string)
}
if urltemplate, ok := paramsMap["urlTemplate"]; ok {
fieldFormatParams.Urltemplate = urltemplate.(string)
}
if labeltemplate, ok := paramsMap["labelTemplate"]; ok {
fieldFormatParams.Labeltemplate = labeltemplate.(string)
}
}
}
Expand Down Expand Up @@ -600,7 +613,9 @@ func tfFieldFormatsToAPI(ctx context.Context, fieldFormats types.Map) (map[strin
}

apiParams = &apiFieldFormatParams{
Pattern: tfParams.Pattern.ValueString(),
Pattern: tfParams.Pattern.ValueString(),
Urltemplate: tfParams.Urltemplate.ValueString(),
Labeltemplate: tfParams.Labeltemplate.ValueString(),
}
}

Expand Down Expand Up @@ -658,9 +673,13 @@ type apiFieldFormat struct {
}

type tfFieldFormatParamsV0 struct {
Pattern types.String `tfsdk:"pattern"`
Pattern types.String `tfsdk:"pattern"`
Urltemplate types.String `tfsdk:"urltemplate"`
Labeltemplate types.String `tfsdk:"labeltemplate"`
}

type apiFieldFormatParams struct {
Pattern string `tfsdk:"pattern" json:"pattern"`
Pattern string `tfsdk:"pattern" json:"pattern,omitempty"`
Urltemplate string `tfsdk:"urltemplate" json:"urlTemplate,omitempty"`
Labeltemplate string `tfsdk:"labeltemplate" json:"labelTemplate,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should potentially be *string since they're optional in the schema.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what I was missing! Thanks for the assist. Changes made and pushed.

}
16 changes: 12 additions & 4 deletions internal/kibana/data_view/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func Test_tfModelV0_ToCreateRequest(t *testing.T) {
"field1": {
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: "0.00",
Urltemplate: "https://test.com/{{value}}",
Labeltemplate: "{{value}}",
},
},
},
Expand All @@ -66,7 +68,9 @@ func Test_tfModelV0_ToCreateRequest(t *testing.T) {
"field1": apiFieldFormat{
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: "0.00",
Urltemplate: "https://test.com/{{value}}",
Labeltemplate: "{{value}}",
},
},
},
Expand Down Expand Up @@ -161,7 +165,9 @@ func Test_tfModelV0_ToUpdateRequest(t *testing.T) {
"field1": {
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: "0.00",
Urltemplate: "https://test.com/{{value}}",
Labeltemplate: "{{value}}",
},
},
},
Expand All @@ -176,7 +182,9 @@ func Test_tfModelV0_ToUpdateRequest(t *testing.T) {
"field1": apiFieldFormat{
ID: "field1",
Params: &apiFieldFormatParams{
Pattern: "0.00",
Pattern: "0.00",
Urltemplate: "https://test.com/{{value}}",
Labeltemplate: "{{value}}",
},
},
},
Expand Down
Loading