Skip to content

Additional dataview field formats #1001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- 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))
- Add `max_primary_shard_docs` condition to ILM rollover ([#845](https://github.com/elastic/terraform-provider-elasticstack/pull/845))
- Add missing entries to `data_view.field_formats.params` ([#1001](https://github.com/elastic/terraform-provider-elasticstack/pull/1001))

## [0.11.13] - 2025-01-09

Expand Down
154 changes: 150 additions & 4 deletions docs/resources/kibana_data_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,117 @@ resource "elasticstack_kibana_data_view" "my_data_view" {
namespaces = ["backend"]
}
}

resource "elasticstack_kibana_data_view" "custom_fields_data_view" {
data_view = {
name = "custom-data-view"
id = "custom-data-view"
title = "logs-*"
time_field_name = "@timestamp"
namespaces = ["default"]
field_formats = {
"host.uptime" = {
id = "duration"
params = {
input_format = "hours"
output_format = "humanizePrecise"
output_precision = 2
include_space_with_suffix = true
use_short_suffix = true
}
}
"user.last_password_change" = {
id = "relative_date"
params = {}
}
"user.last_login" = {
id = "date"
params = {
pattern = "MMM D, YYYY @ HH:mm:ss.SSS"
timezone = "America/New_York"
}
}
"user.is_active" = {
id = "boolean"
params = {}
}
"user.status" = {
id = "color"
params = {
field_type = "string"
colors = [
{
range = "-Infinity:Infinity"
regex = "inactive*"
text = "#000000"
background = "#ffffff"
}
]
}
}
"user.message" = {
id = "truncate"
params = {
field_length = 10
}
}
"host.name" = {
id = "string"
params = {
transform = "upper"
}
}
"response.code" = {
id = "static_lookup"
params = {
lookup_entries = [
{
key = "200"
value = "OK"
},
{
key = "404"
value = "Not Found"
}
]
unknown_key_value = "Unknown"
}
}
"url.original" = {
id = "url"
params = {
type = "a"
urltemplate = "https://test.com/{{value}}"
labeltemplate = "{{value}}"
}
}
"user.profile_picture" = {
id = "url"
params = {
type = "img"
urltemplate = "https://test.com/{{value}}"
labeltemplate = "{{value}}"
width = 6
height = 4
}
}
"user.answering_message" = {
id = "url"
params = {
type = "audio"
urltemplate = "https://test.com/{{value}}"
labeltemplate = "{{value}}"
}
}
}
field_attrs = {
"response.code" = {
custom_label = "Response Code"
count = 0
}
}
}
}
```

<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -77,7 +188,7 @@ Optional:

Required:

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

Optional:

Expand All @@ -88,9 +199,44 @@ Optional:

Optional:

- `labeltemplate` (String)
- `pattern` (String)
- `urltemplate` (String)
- `colors` (Attributes List) Color rules for the field. (see [below for nested schema](#nestedatt--data_view--field_formats--params--colors))
- `field_length` (Number) Length to truncate the field value.
- `field_type` (String) Field type for color formatting (e.g., `string`, `number`).
- `height` (Number) Height for image type URLs.
- `include_space_with_suffix` (Boolean) Whether to include a space before the suffix in duration format.
- `input_format` (String) Input format for duration fields (e.g., `hours`, `minutes`).
- `labeltemplate` (String) Label template for the field value.
- `lookup_entries` (Attributes List) Key-value pairs for static lookup. (see [below for nested schema](#nestedatt--data_view--field_formats--params--lookup_entries))
- `output_format` (String) Output format for duration fields (e.g., `humanizePrecise`, `humanize`).
- `output_precision` (Number) Precision for duration output.
- `pattern` (String) Pattern for formatting the field value.
- `timezone` (String) Timezone for date formatting (e.g., `America/New_York`).
- `transform` (String) Transform to apply to string fields (e.g., `upper`, `lower`).
- `type` (String) Type of URL format (e.g., `a`, `img`, `audio`).
- `unknown_key_value` (String) Value to display when key is not found in lookup.
- `urltemplate` (String) URL template for the field value.
- `use_short_suffix` (Boolean) Whether to use short suffixes in duration format.
- `width` (Number) Width for image type URLs.

<a id="nestedatt--data_view--field_formats--params--colors"></a>
### Nested Schema for `data_view.field_formats.params.width`

Optional:

- `background` (String) Background color in hex format.
- `range` (String) Range for the color rule (e.g., `-Infinity:Infinity`).
- `regex` (String) Regex pattern for the color rule.
- `text` (String) Text color in hex format.


<a id="nestedatt--data_view--field_formats--params--lookup_entries"></a>
### Nested Schema for `data_view.field_formats.params.width`

Required:

- `key` (String) Key for the lookup entry.
- `value` (String) Value for the lookup entry.




Expand Down
111 changes: 111 additions & 0 deletions examples/resources/elasticstack_kibana_data_view/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,114 @@ resource "elasticstack_kibana_data_view" "my_data_view" {
namespaces = ["backend"]
}
}

resource "elasticstack_kibana_data_view" "custom_fields_data_view" {
data_view = {
name = "custom-data-view"
id = "custom-data-view"
title = "logs-*"
time_field_name = "@timestamp"
namespaces = ["default"]
field_formats = {
"host.uptime" = {
id = "duration"
params = {
input_format = "hours"
output_format = "humanizePrecise"
output_precision = 2
include_space_with_suffix = true
use_short_suffix = true
}
}
"user.last_password_change" = {
id = "relative_date"
params = {}
}
"user.last_login" = {
id = "date"
params = {
pattern = "MMM D, YYYY @ HH:mm:ss.SSS"
timezone = "America/New_York"
}
}
"user.is_active" = {
id = "boolean"
params = {}
}
"user.status" = {
id = "color"
params = {
field_type = "string"
colors = [
{
range = "-Infinity:Infinity"
regex = "inactive*"
text = "#000000"
background = "#ffffff"
}
]
}
}
"user.message" = {
id = "truncate"
params = {
field_length = 10
}
}
"host.name" = {
id = "string"
params = {
transform = "upper"
}
}
"response.code" = {
id = "static_lookup"
params = {
lookup_entries = [
{
key = "200"
value = "OK"
},
{
key = "404"
value = "Not Found"
}
]
unknown_key_value = "Unknown"
}
}
"url.original" = {
id = "url"
params = {
type = "a"
urltemplate = "https://test.com/{{value}}"
labeltemplate = "{{value}}"
}
}
"user.profile_picture" = {
id = "url"
params = {
type = "img"
urltemplate = "https://test.com/{{value}}"
labeltemplate = "{{value}}"
width = 6
height = 4
}
}
"user.answering_message" = {
id = "url"
params = {
type = "audio"
urltemplate = "https://test.com/{{value}}"
labeltemplate = "{{value}}"
}
}
}
field_attrs = {
"response.code" = {
custom_label = "Response Code"
count = 0
}
}
}
}
4 changes: 2 additions & 2 deletions generated/kbapi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SHELL := /bin/bash
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

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

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

oas.yaml:
curl -sSo oas.yaml "$(oas_url)"
curl -sSfo oas.yaml "$(oas_url)"

.PHONY: transform
transform: download ## Transform and filter the schema
Expand Down
45 changes: 38 additions & 7 deletions generated/kbapi/kibana.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading