Skip to content

Commit

Permalink
Use Kibana for version checks if ES is not configured (#869)
Browse files Browse the repository at this point in the history
* Use Kibana for version checks if ES is not configured

* Changelog
  • Loading branch information
tobio authored Oct 23, 2024
1 parent adc85c1 commit f58fb83
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased]

- Allow `elasticstack_kibana_alerting_rule` to be used without Elasticsearch being configured. ([#869](https://github.com/elastic/terraform-provider-elasticstack/pull/869))
- Add resource `elasticstack_elasticsearch_data_stream_lifecycle` ([838](https://github.com/elastic/terraform-provider-elasticstack/issues/838))

## [0.11.10] - 2024-10-23
Expand Down Expand Up @@ -379,8 +380,8 @@
- CI integration

[Unreleased]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.10...HEAD
[0.11.9]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.9...v0.11.10
[0.11.8]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.8...v0.11.9
[0.11.10]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.9...v0.11.10
[0.11.9]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.8...v0.11.9
[0.11.8]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.7...v0.11.8
[0.11.7]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.6...v0.11.7
[0.11.6]: https://github.com/elastic/terraform-provider-elasticstack/compare/v0.11.5...v0.11.6
Expand Down
37 changes: 37 additions & 0 deletions internal/clients/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,43 @@ func (a *ApiClient) serverInfo(ctx context.Context) (*models.ClusterInfo, diag.D
}

func (a *ApiClient) ServerVersion(ctx context.Context) (*version.Version, diag.Diagnostics) {
if a.elasticsearch != nil {
return a.versionFromElasticsearch(ctx)
}

return a.versionFromKibana()
}

func (a *ApiClient) versionFromKibana() (*version.Version, diag.Diagnostics) {
kibClient, err := a.GetKibanaClient()
if err != nil {
return nil, diag.FromErr(err)
}

status, err := kibClient.KibanaStatus.Get()
if err != nil {
return nil, diag.FromErr(err)
}

vMap, ok := status["version"].(map[string]interface{})
if !ok {
return nil, diag.Errorf("failed to get version from Kibana API")
}

rawVersion, ok := vMap["number"].(string)
if !ok {
return nil, diag.Errorf("failed to get version number from Kibana status")
}

serverVersion, err := version.NewVersion(rawVersion)
if err != nil {
return nil, diag.FromErr(err)
}

return serverVersion, nil
}

func (a *ApiClient) versionFromElasticsearch(ctx context.Context) (*version.Version, diag.Diagnostics) {
info, diags := a.serverInfo(ctx)
if diags.HasError() {
return nil, diags
Expand Down
8 changes: 0 additions & 8 deletions internal/kibana/alerting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ func TestAccResourceAlertingRule(t *testing.T) {
func testAccResourceAlertingRuleCreate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -221,7 +220,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleUpdate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -256,7 +254,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleWithFrequencyCreate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -314,7 +311,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleWithFrequencyUpdate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -375,7 +371,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleWithAlertsFilterCreate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -450,7 +445,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleWithAlertsFilterUpdate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -527,7 +521,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleWithAlertDelayCreate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down Expand Up @@ -587,7 +580,6 @@ resource "elasticstack_kibana_alerting_rule" "test_rule" {
func testAccResourceAlertingRuleWithAlertDelayUpdate(name string) string {
return fmt.Sprintf(`
provider "elasticstack" {
elasticsearch {}
kibana {}
}
Expand Down

0 comments on commit f58fb83

Please sign in to comment.