From 1fefa8daf8e6470afc52513db352cb130de8165e Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Mon, 14 Oct 2024 12:18:40 +0200 Subject: [PATCH 1/2] fix: Elastic Indices datasource boolean parsing --- internal/elasticsearch/index/indices/models.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/elasticsearch/index/indices/models.go b/internal/elasticsearch/index/indices/models.go index e548edef3..45def0424 100644 --- a/internal/elasticsearch/index/indices/models.go +++ b/internal/elasticsearch/index/indices/models.go @@ -284,6 +284,20 @@ func setSettingsFromAPI(ctx context.Context, model *indexTfModel, apiModel model } tfValue = basetypes.NewStringValue(settingStr) case types.Bool: + if settingStr, ok := settingsValue.(string); ok { + settingBool, err := strconv.ParseBool(settingStr) + if err != nil { + return diag.Diagnostics{ + diag.NewErrorDiagnostic( + "failed to convert setting to bool", + fmt.Sprintf("expected setting to be a bool but it was a string. Attempted to parse it but got %s", err.Error()), + ), + } + } + + settingsValue = bool(settingBool) + } + settingBool, ok := settingsValue.(bool) if !ok { return diag.Diagnostics{ @@ -300,7 +314,7 @@ func setSettingsFromAPI(ctx context.Context, model *indexTfModel, apiModel model return diag.Diagnostics{ diag.NewErrorDiagnostic( "failed to convert setting to int", - fmt.Sprintf("expected setting to be an in but it was a string. Attempted to parse it but got %s", err.Error()), + fmt.Sprintf("expected setting to be an int but it was a string. Attempted to parse it but got %s", err.Error()), ), } } From ee5e1930d11b244490b86cf984a36920aede7401 Mon Sep 17 00:00:00 2001 From: Jordan DESNOES Date: Tue, 15 Oct 2024 08:36:16 +0200 Subject: [PATCH 2/2] fix: Elastic Indices datasource boolean parsing --- CHANGELOG.md | 4 ++++ internal/elasticsearch/index/indices/models.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1f622804..45990b649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +### Changes + +- Fix boolean setting parsing for `elasticstack_elasticsearch_indices` data source. ([#842](https://github.com/elastic/terraform-provider-elasticstack/pull/842)) + ## [0.11.9] - 2024-10-14 ### Breaking changes diff --git a/internal/elasticsearch/index/indices/models.go b/internal/elasticsearch/index/indices/models.go index 45def0424..35e08d00d 100644 --- a/internal/elasticsearch/index/indices/models.go +++ b/internal/elasticsearch/index/indices/models.go @@ -295,7 +295,7 @@ func setSettingsFromAPI(ctx context.Context, model *indexTfModel, apiModel model } } - settingsValue = bool(settingBool) + settingsValue = settingBool } settingBool, ok := settingsValue.(bool)