Skip to content

Commit 33887bf

Browse files
Copilottobio
andcommitted
Add version checking for solution field in Kibana space resource
Co-authored-by: tobio <[email protected]>
1 parent 0a8ad80 commit 33887bf

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

internal/kibana/space.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import (
66

77
"github.com/disaster37/go-kibana-rest/v8/kbapi"
88
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
9+
"github.com/hashicorp/go-version"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1213
)
1314

15+
var SpaceSolutionMinVersion = version.Must(version.NewVersion("8.18.0"))
16+
1417
func ResourceSpace() *schema.Resource {
1518
apikeySchema := map[string]*schema.Schema{
1619
"id": {
@@ -96,6 +99,18 @@ func resourceSpaceUpsert(ctx context.Context, d *schema.ResourceData, meta inter
9699
return diag.FromErr(err)
97100
}
98101

102+
// Check version compatibility for solution field
103+
if solution, ok := d.GetOk("solution"); ok && solution.(string) != "" {
104+
serverVersion, diags := client.ServerVersion(ctx)
105+
if diags.HasError() {
106+
return diags
107+
}
108+
109+
if !serverVersion.GreaterThanOrEqual(SpaceSolutionMinVersion) {
110+
return diag.Errorf("solution field is not supported in this version of the Elastic Stack. Solution field requires %s or higher", SpaceSolutionMinVersion)
111+
}
112+
}
113+
99114
space := kbapi.KibanaSpace{
100115
ID: d.Get("space_id").(string),
101116
Name: d.Get("name").(string),

0 commit comments

Comments
 (0)