From a1c399fc04853f0e716df30cb42e1488dcf48f68 Mon Sep 17 00:00:00 2001 From: Ahmad Ragab Date: Mon, 29 Apr 2024 22:06:15 -0400 Subject: [PATCH 1/4] checking pattern --- internal/kibana/data_view/schema.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/kibana/data_view/schema.go b/internal/kibana/data_view/schema.go index c12bab8b..86487c81 100644 --- a/internal/kibana/data_view/schema.go +++ b/internal/kibana/data_view/schema.go @@ -343,8 +343,10 @@ func dataViewFromResponse(resp data_views.DataViewResponseObjectDataView) apiDat } if params, ok := formatMap["params"].(map[string]interface{}); ok { - apiFormat.Params = &apiFieldFormatParams{ - Pattern: params["pattern"].(string), + if pattern, ok := params["pattern"]; ok { + apiFormat.Params = &apiFieldFormatParams{ + Pattern: pattern.(string), + } } } From deac3b0fe08d98cbf0001de7e4e9fb5fe556140f Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Tue, 30 Apr 2024 13:56:05 +1000 Subject: [PATCH 2/4] Also check if the params key exists --- internal/kibana/data_view/schema.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/kibana/data_view/schema.go b/internal/kibana/data_view/schema.go index 86487c81..b0cd8b0f 100644 --- a/internal/kibana/data_view/schema.go +++ b/internal/kibana/data_view/schema.go @@ -342,11 +342,10 @@ func dataViewFromResponse(resp data_views.DataViewResponseObjectDataView) apiDat ID: formatMap["id"].(string), } - if params, ok := formatMap["params"].(map[string]interface{}); ok { - if pattern, ok := params["pattern"]; ok { - apiFormat.Params = &apiFieldFormatParams{ - Pattern: pattern.(string), - } + if params, ok := formatMap["params"]; ok { + paramsMap := params.(map[string]interface{}) + if pattern, ok := paramsMap["pattern"]; ok { + apiFormat.Params = &apiFieldFormatParams{Pattern: pattern.(string)} } } From a740225a6a2b7715ec7a88ab7a77995b651d73a8 Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Tue, 30 Apr 2024 13:58:19 +1000 Subject: [PATCH 3/4] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd7ddd2f..204378a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Prevent a provider panic when an `elasticstack_elasticsearch_template` or `elasticstack_elasticsearch_component_template` includes an empty `template` (`template {}`) block. ([#598](https://github.com/elastic/terraform-provider-elasticstack/pull/598)) - Prevent `elasticstack_kibana_space` to attempt the space recreation if `initials` and `color` are not provided. ([#606](https://github.com/elastic/terraform-provider-elasticstack/pull/606)) +- Prevent a provider panic in `elasticstack_kibana_data_view` when a `field_format` does not include a `pattern`. ([#619](https://github.com/elastic/terraform-provider-elasticstack/pull/619/files)) ### Added From dcc149543e98912966977107e542161f07497f88 Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Tue, 30 Apr 2024 14:12:58 +1000 Subject: [PATCH 4/4] And check the params type conversion --- internal/kibana/data_view/schema.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/kibana/data_view/schema.go b/internal/kibana/data_view/schema.go index b0cd8b0f..e6e484bb 100644 --- a/internal/kibana/data_view/schema.go +++ b/internal/kibana/data_view/schema.go @@ -343,9 +343,10 @@ func dataViewFromResponse(resp data_views.DataViewResponseObjectDataView) apiDat } if params, ok := formatMap["params"]; ok { - paramsMap := params.(map[string]interface{}) - if pattern, ok := paramsMap["pattern"]; ok { - apiFormat.Params = &apiFieldFormatParams{Pattern: pattern.(string)} + if paramsMap, ok := params.(map[string]interface{}); ok { + if pattern, ok := paramsMap["pattern"]; ok { + apiFormat.Params = &apiFieldFormatParams{Pattern: pattern.(string)} + } } }