Skip to content

Commit b1caa1e

Browse files
Additional dataview field formats (elastic#1001)
* first pass * update transform schema * cleanup * regen kbapi * fix things * fix an error? * fix * lint * docs * model tests passing * cleanup * gen from original PR date instead * fail curl on 4xx, change date to 11-19 * fmt * revert makefile * cl * update example resource * fmt * docs --------- Co-authored-by: Caleb Crouse <[email protected]>
1 parent 5caf183 commit b1caa1e

File tree

9 files changed

+953
-32
lines changed

9 files changed

+953
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Fix a provider crash when interacting with elasticstack_kibana_data_view resources created with 0.11.0. ([#979](https://github.com/elastic/terraform-provider-elasticstack/pull/979))
44
- Add `max_primary_shard_docs` condition to ILM rollover ([#845](https://github.com/elastic/terraform-provider-elasticstack/pull/845))
5+
- Add missing entries to `data_view.field_formats.params` ([#1001](https://github.com/elastic/terraform-provider-elasticstack/pull/1001))
56

67
## [0.11.13] - 2025-01-09
78

docs/resources/kibana_data_view.md

Lines changed: 150 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,117 @@ resource "elasticstack_kibana_data_view" "my_data_view" {
2626
namespaces = ["backend"]
2727
}
2828
}
29+
30+
resource "elasticstack_kibana_data_view" "custom_fields_data_view" {
31+
data_view = {
32+
name = "custom-data-view"
33+
id = "custom-data-view"
34+
title = "logs-*"
35+
time_field_name = "@timestamp"
36+
namespaces = ["default"]
37+
field_formats = {
38+
"host.uptime" = {
39+
id = "duration"
40+
params = {
41+
input_format = "hours"
42+
output_format = "humanizePrecise"
43+
output_precision = 2
44+
include_space_with_suffix = true
45+
use_short_suffix = true
46+
}
47+
}
48+
"user.last_password_change" = {
49+
id = "relative_date"
50+
params = {}
51+
}
52+
"user.last_login" = {
53+
id = "date"
54+
params = {
55+
pattern = "MMM D, YYYY @ HH:mm:ss.SSS"
56+
timezone = "America/New_York"
57+
}
58+
}
59+
"user.is_active" = {
60+
id = "boolean"
61+
params = {}
62+
}
63+
"user.status" = {
64+
id = "color"
65+
params = {
66+
field_type = "string"
67+
colors = [
68+
{
69+
range = "-Infinity:Infinity"
70+
regex = "inactive*"
71+
text = "#000000"
72+
background = "#ffffff"
73+
}
74+
]
75+
}
76+
}
77+
"user.message" = {
78+
id = "truncate"
79+
params = {
80+
field_length = 10
81+
}
82+
}
83+
"host.name" = {
84+
id = "string"
85+
params = {
86+
transform = "upper"
87+
}
88+
}
89+
"response.code" = {
90+
id = "static_lookup"
91+
params = {
92+
lookup_entries = [
93+
{
94+
key = "200"
95+
value = "OK"
96+
},
97+
{
98+
key = "404"
99+
value = "Not Found"
100+
}
101+
]
102+
unknown_key_value = "Unknown"
103+
}
104+
}
105+
"url.original" = {
106+
id = "url"
107+
params = {
108+
type = "a"
109+
urltemplate = "https://test.com/{{value}}"
110+
labeltemplate = "{{value}}"
111+
}
112+
}
113+
"user.profile_picture" = {
114+
id = "url"
115+
params = {
116+
type = "img"
117+
urltemplate = "https://test.com/{{value}}"
118+
labeltemplate = "{{value}}"
119+
width = 6
120+
height = 4
121+
}
122+
}
123+
"user.answering_message" = {
124+
id = "url"
125+
params = {
126+
type = "audio"
127+
urltemplate = "https://test.com/{{value}}"
128+
labeltemplate = "{{value}}"
129+
}
130+
}
131+
}
132+
field_attrs = {
133+
"response.code" = {
134+
custom_label = "Response Code"
135+
count = 0
136+
}
137+
}
138+
}
139+
}
29140
```
30141

31142
<!-- schema generated by tfplugindocs -->
@@ -77,7 +188,7 @@ Optional:
77188

78189
Required:
79190

80-
- `id` (String)
191+
- `id` (String) The ID of the field format. Valid values include: `boolean`, `color`, `date`, `duration`, `number`, `percent`, `relative_date`, `static_lookup`, `string`, `truncate`, `url`.
81192

82193
Optional:
83194

@@ -88,9 +199,44 @@ Optional:
88199

89200
Optional:
90201

91-
- `labeltemplate` (String)
92-
- `pattern` (String)
93-
- `urltemplate` (String)
202+
- `colors` (Attributes List) Color rules for the field. (see [below for nested schema](#nestedatt--data_view--field_formats--params--colors))
203+
- `field_length` (Number) Length to truncate the field value.
204+
- `field_type` (String) Field type for color formatting (e.g., `string`, `number`).
205+
- `height` (Number) Height for image type URLs.
206+
- `include_space_with_suffix` (Boolean) Whether to include a space before the suffix in duration format.
207+
- `input_format` (String) Input format for duration fields (e.g., `hours`, `minutes`).
208+
- `labeltemplate` (String) Label template for the field value.
209+
- `lookup_entries` (Attributes List) Key-value pairs for static lookup. (see [below for nested schema](#nestedatt--data_view--field_formats--params--lookup_entries))
210+
- `output_format` (String) Output format for duration fields (e.g., `humanizePrecise`, `humanize`).
211+
- `output_precision` (Number) Precision for duration output.
212+
- `pattern` (String) Pattern for formatting the field value.
213+
- `timezone` (String) Timezone for date formatting (e.g., `America/New_York`).
214+
- `transform` (String) Transform to apply to string fields (e.g., `upper`, `lower`).
215+
- `type` (String) Type of URL format (e.g., `a`, `img`, `audio`).
216+
- `unknown_key_value` (String) Value to display when key is not found in lookup.
217+
- `urltemplate` (String) URL template for the field value.
218+
- `use_short_suffix` (Boolean) Whether to use short suffixes in duration format.
219+
- `width` (Number) Width for image type URLs.
220+
221+
<a id="nestedatt--data_view--field_formats--params--colors"></a>
222+
### Nested Schema for `data_view.field_formats.params.width`
223+
224+
Optional:
225+
226+
- `background` (String) Background color in hex format.
227+
- `range` (String) Range for the color rule (e.g., `-Infinity:Infinity`).
228+
- `regex` (String) Regex pattern for the color rule.
229+
- `text` (String) Text color in hex format.
230+
231+
232+
<a id="nestedatt--data_view--field_formats--params--lookup_entries"></a>
233+
### Nested Schema for `data_view.field_formats.params.width`
234+
235+
Required:
236+
237+
- `key` (String) Key for the lookup entry.
238+
- `value` (String) Value for the lookup entry.
239+
94240

95241

96242

examples/resources/elasticstack_kibana_data_view/resource.tf

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,114 @@ resource "elasticstack_kibana_data_view" "my_data_view" {
1111
namespaces = ["backend"]
1212
}
1313
}
14+
15+
resource "elasticstack_kibana_data_view" "custom_fields_data_view" {
16+
data_view = {
17+
name = "custom-data-view"
18+
id = "custom-data-view"
19+
title = "logs-*"
20+
time_field_name = "@timestamp"
21+
namespaces = ["default"]
22+
field_formats = {
23+
"host.uptime" = {
24+
id = "duration"
25+
params = {
26+
input_format = "hours"
27+
output_format = "humanizePrecise"
28+
output_precision = 2
29+
include_space_with_suffix = true
30+
use_short_suffix = true
31+
}
32+
}
33+
"user.last_password_change" = {
34+
id = "relative_date"
35+
params = {}
36+
}
37+
"user.last_login" = {
38+
id = "date"
39+
params = {
40+
pattern = "MMM D, YYYY @ HH:mm:ss.SSS"
41+
timezone = "America/New_York"
42+
}
43+
}
44+
"user.is_active" = {
45+
id = "boolean"
46+
params = {}
47+
}
48+
"user.status" = {
49+
id = "color"
50+
params = {
51+
field_type = "string"
52+
colors = [
53+
{
54+
range = "-Infinity:Infinity"
55+
regex = "inactive*"
56+
text = "#000000"
57+
background = "#ffffff"
58+
}
59+
]
60+
}
61+
}
62+
"user.message" = {
63+
id = "truncate"
64+
params = {
65+
field_length = 10
66+
}
67+
}
68+
"host.name" = {
69+
id = "string"
70+
params = {
71+
transform = "upper"
72+
}
73+
}
74+
"response.code" = {
75+
id = "static_lookup"
76+
params = {
77+
lookup_entries = [
78+
{
79+
key = "200"
80+
value = "OK"
81+
},
82+
{
83+
key = "404"
84+
value = "Not Found"
85+
}
86+
]
87+
unknown_key_value = "Unknown"
88+
}
89+
}
90+
"url.original" = {
91+
id = "url"
92+
params = {
93+
type = "a"
94+
urltemplate = "https://test.com/{{value}}"
95+
labeltemplate = "{{value}}"
96+
}
97+
}
98+
"user.profile_picture" = {
99+
id = "url"
100+
params = {
101+
type = "img"
102+
urltemplate = "https://test.com/{{value}}"
103+
labeltemplate = "{{value}}"
104+
width = 6
105+
height = 4
106+
}
107+
}
108+
"user.answering_message" = {
109+
id = "url"
110+
params = {
111+
type = "audio"
112+
urltemplate = "https://test.com/{{value}}"
113+
labeltemplate = "{{value}}"
114+
}
115+
}
116+
}
117+
field_attrs = {
118+
"response.code" = {
119+
custom_label = "Response Code"
120+
count = 0
121+
}
122+
}
123+
}
124+
}

generated/kbapi/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
SHELL := /bin/bash
33
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
44

5-
github_ref := refs/heads/main
5+
github_ref ?= refs/heads/main
66
oas_url := https://raw.githubusercontent.com/elastic/kibana/$(github_ref)/oas_docs/output/kibana.yaml
77

88
.PHONY: all
@@ -13,7 +13,7 @@ all: download transform generate ## Fetch, bundle, transform, and generate the A
1313
download: oas.yaml ## Download the remote schema
1414

1515
oas.yaml:
16-
curl -sSo oas.yaml "$(oas_url)"
16+
curl -sSfo oas.yaml "$(oas_url)"
1717

1818
.PHONY: transform
1919
transform: download ## Transform and filter the schema

generated/kbapi/kibana.gen.go

Lines changed: 38 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)