From c98d112404ff0dd8a363f32088aaae02a507c9d6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Oct 2025 22:29:37 +0000 Subject: [PATCH 1/6] Initial plan From 989dc3172a5e6249d3d32996ee887716857e0cba Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Oct 2025 22:42:15 +0000 Subject: [PATCH 2/6] Add kibana_default_data_view resource with CRUD operations Co-authored-by: tobio <444668+tobio@users.noreply.github.com> --- internal/clients/kibana_oapi/data_views.go | 33 ++++ internal/kibana/default_data_view/acc_test.go | 154 ++++++++++++++++++ internal/kibana/default_data_view/create.go | 46 ++++++ internal/kibana/default_data_view/delete.go | 41 +++++ internal/kibana/default_data_view/models.go | 12 ++ internal/kibana/default_data_view/read.go | 44 +++++ internal/kibana/default_data_view/resource.go | 33 ++++ internal/kibana/default_data_view/schema.go | 51 ++++++ internal/kibana/default_data_view/update.go | 46 ++++++ provider/plugin_framework.go | 2 + 10 files changed, 462 insertions(+) create mode 100644 internal/kibana/default_data_view/acc_test.go create mode 100644 internal/kibana/default_data_view/create.go create mode 100644 internal/kibana/default_data_view/delete.go create mode 100644 internal/kibana/default_data_view/models.go create mode 100644 internal/kibana/default_data_view/read.go create mode 100644 internal/kibana/default_data_view/resource.go create mode 100644 internal/kibana/default_data_view/schema.go create mode 100644 internal/kibana/default_data_view/update.go diff --git a/internal/clients/kibana_oapi/data_views.go b/internal/clients/kibana_oapi/data_views.go index 1126a73cc..e20e1bbd1 100644 --- a/internal/clients/kibana_oapi/data_views.go +++ b/internal/clients/kibana_oapi/data_views.go @@ -87,3 +87,36 @@ func DeleteDataView(ctx context.Context, client *Client, spaceID string, viewID return reportUnknownError(resp.StatusCode(), resp.Body) } } + +// GetDefaultDataView reads the default data view from the API. +func GetDefaultDataView(ctx context.Context, client *Client) (*string, diag.Diagnostics) { + resp, err := client.API.GetDefaultDataViewDefaultWithResponse(ctx) + if err != nil { + return nil, diagutil.FrameworkDiagFromError(err) + } + + switch resp.StatusCode() { + case http.StatusOK: + if resp.JSON200 != nil && resp.JSON200.DataViewId != nil { + return resp.JSON200.DataViewId, nil + } + return nil, nil + default: + return nil, reportUnknownError(resp.StatusCode(), resp.Body) + } +} + +// SetDefaultDataView sets the default data view. +func SetDefaultDataView(ctx context.Context, client *Client, req kbapi.SetDefaultDatailViewDefaultJSONRequestBody) diag.Diagnostics { + resp, err := client.API.SetDefaultDatailViewDefaultWithResponse(ctx, req) + if err != nil { + return diagutil.FrameworkDiagFromError(err) + } + + switch resp.StatusCode() { + case http.StatusOK: + return nil + default: + return reportUnknownError(resp.StatusCode(), resp.Body) + } +} diff --git a/internal/kibana/default_data_view/acc_test.go b/internal/kibana/default_data_view/acc_test.go new file mode 100644 index 000000000..6efffeb4d --- /dev/null +++ b/internal/kibana/default_data_view/acc_test.go @@ -0,0 +1,154 @@ +package default_data_view_test + +import ( + "fmt" + "testing" + + "github.com/elastic/terraform-provider-elasticstack/internal/acctest" + "github.com/elastic/terraform-provider-elasticstack/internal/versionutils" + "github.com/hashicorp/go-version" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +var minDataViewAPISupport = version.Must(version.NewVersion("8.1.0")) + +func TestAccResourceDefaultDataView(t *testing.T) { + indexName1 := "my-index-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) + indexName2 := "my-other-index-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.Providers, + Steps: []resource.TestStep{ + { + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), + Config: testAccResourceDefaultDataViewBasic(indexName1), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "id"), + resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "force", "true"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "skip_delete", "false"), + ), + }, + { + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), + Config: testAccResourceDefaultDataViewUpdate(indexName1, indexName2), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "id"), + resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), + ), + }, + }, + }) +} + +func TestAccResourceDefaultDataViewWithSkipDelete(t *testing.T) { + indexName := "my-index-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.Providers, + Steps: []resource.TestStep{ + { + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), + Config: testAccResourceDefaultDataViewWithSkipDelete(indexName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "skip_delete", "true"), + ), + }, + }, + }) +} + +func testAccResourceDefaultDataViewBasic(indexName string) string { + return fmt.Sprintf(` +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = "%s" + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "%s*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + data_view_id = elasticstack_kibana_data_view.dv.data_view.id + force = true +} +`, indexName, indexName) +} + +func testAccResourceDefaultDataViewUpdate(indexName1, indexName2 string) string { + return fmt.Sprintf(` +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = "%s" + deletion_protection = false +} + +resource "elasticstack_elasticsearch_index" "my_other_index" { + name = "%s" + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "%s*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_data_view" "dv2" { + data_view = { + title = "%s*" + } + depends_on = [elasticstack_elasticsearch_index.my_other_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + data_view_id = elasticstack_kibana_data_view.dv2.data_view.id + force = true +} +`, indexName1, indexName2, indexName1, indexName2) +} + +func testAccResourceDefaultDataViewWithSkipDelete(indexName string) string { + return fmt.Sprintf(` +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = "%s" + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "%s*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + data_view_id = elasticstack_kibana_data_view.dv.data_view.id + force = true + skip_delete = true +} +`, indexName, indexName) +} diff --git a/internal/kibana/default_data_view/create.go b/internal/kibana/default_data_view/create.go new file mode 100644 index 000000000..8991854b0 --- /dev/null +++ b/internal/kibana/default_data_view/create.go @@ -0,0 +1,46 @@ +package default_data_view + +import ( + "context" + "fmt" + + "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" + "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (r *DefaultDataViewResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan defaultDataViewModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + client, err := r.client.GetKibanaOapiClient() + if err != nil { + resp.Diagnostics.AddError("unable to get kibana client", err.Error()) + return + } + + dataViewID := plan.DataViewID.ValueString() + force := plan.Force.ValueBool() + + setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ + DataViewId: &dataViewID, + Force: &force, + } + + diags = kibana_oapi.SetDefaultDataView(ctx, client, setReq) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // Set the ID to the data view ID for state tracking + plan.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", dataViewID)) + + diags = resp.State.Set(ctx, plan) + resp.Diagnostics.Append(diags...) +} diff --git a/internal/kibana/default_data_view/delete.go b/internal/kibana/default_data_view/delete.go new file mode 100644 index 000000000..7b3fdcbd2 --- /dev/null +++ b/internal/kibana/default_data_view/delete.go @@ -0,0 +1,41 @@ +package default_data_view + +import ( + "context" + + "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" + "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +func (r *DefaultDataViewResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + var state defaultDataViewModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // If skip_delete is true, leave the default data view unchanged + if state.SkipDelete.ValueBool() { + return + } + + client, err := r.client.GetKibanaOapiClient() + if err != nil { + resp.Diagnostics.AddError("unable to get kibana client", err.Error()) + return + } + + // Unset the default data view by setting it to null + var nullDataViewID *string = nil + force := true + + setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ + DataViewId: nullDataViewID, + Force: &force, + } + + diags = kibana_oapi.SetDefaultDataView(ctx, client, setReq) + resp.Diagnostics.Append(diags...) +} diff --git a/internal/kibana/default_data_view/models.go b/internal/kibana/default_data_view/models.go new file mode 100644 index 000000000..8bc5743b1 --- /dev/null +++ b/internal/kibana/default_data_view/models.go @@ -0,0 +1,12 @@ +package default_data_view + +import ( + "github.com/hashicorp/terraform-plugin-framework/types" +) + +type defaultDataViewModel struct { + ID types.String `tfsdk:"id"` + DataViewID types.String `tfsdk:"data_view_id"` + Force types.Bool `tfsdk:"force"` + SkipDelete types.Bool `tfsdk:"skip_delete"` +} diff --git a/internal/kibana/default_data_view/read.go b/internal/kibana/default_data_view/read.go new file mode 100644 index 000000000..42de74fd8 --- /dev/null +++ b/internal/kibana/default_data_view/read.go @@ -0,0 +1,44 @@ +package default_data_view + +import ( + "context" + "fmt" + + "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state defaultDataViewModel + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + client, err := r.client.GetKibanaOapiClient() + if err != nil { + resp.Diagnostics.AddError("unable to get kibana client", err.Error()) + return + } + + defaultDataViewID, diags := kibana_oapi.GetDefaultDataView(ctx, client) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // If no default data view is set, remove from state + if defaultDataViewID == nil || *defaultDataViewID == "" { + resp.State.RemoveResource(ctx) + return + } + + // Update state with current default data view + state.DataViewID = types.StringValue(*defaultDataViewID) + state.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", *defaultDataViewID)) + + diags = resp.State.Set(ctx, state) + resp.Diagnostics.Append(diags...) +} diff --git a/internal/kibana/default_data_view/resource.go b/internal/kibana/default_data_view/resource.go new file mode 100644 index 000000000..dd5d262a0 --- /dev/null +++ b/internal/kibana/default_data_view/resource.go @@ -0,0 +1,33 @@ +package default_data_view + +import ( + "context" + "fmt" + + "github.com/elastic/terraform-provider-elasticstack/internal/clients" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +var ( + _ resource.Resource = &DefaultDataViewResource{} + _ resource.ResourceWithConfigure = &DefaultDataViewResource{} +) + +// NewResource is a helper function to simplify the provider implementation. +func NewResource() resource.Resource { + return &DefaultDataViewResource{} +} + +type DefaultDataViewResource struct { + client *clients.ApiClient +} + +func (r *DefaultDataViewResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + client, diags := clients.ConvertProviderData(req.ProviderData) + resp.Diagnostics.Append(diags...) + r.client = client +} + +func (r *DefaultDataViewResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = fmt.Sprintf("%s_%s", req.ProviderTypeName, "kibana_default_data_view") +} diff --git a/internal/kibana/default_data_view/schema.go b/internal/kibana/default_data_view/schema.go new file mode 100644 index 000000000..945c88879 --- /dev/null +++ b/internal/kibana/default_data_view/schema.go @@ -0,0 +1,51 @@ +package default_data_view + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +func (r *DefaultDataViewResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = getSchema() +} + +func getSchema() schema.Schema { + return schema.Schema{ + MarkdownDescription: "Manages the default Kibana data view. See the [Kibana Data Views API documentation](https://www.elastic.co/docs/api/doc/kibana/v8/operation/operation-setdefaultdatailviewdefault) for more information.", + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "Internal identifier of the resource.", + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, + }, + "data_view_id": schema.StringAttribute{ + MarkdownDescription: "The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Use `null` to unset the default data view.", + Required: true, + Validators: []validator.String{ + stringvalidator.LengthAtLeast(1), + }, + }, + "force": schema.BoolAttribute{ + MarkdownDescription: "Update an existing default data view identifier. If set to false and a default data view already exists, the operation will fail.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(true), + }, + "skip_delete": schema.BoolAttribute{ + MarkdownDescription: "If set to true, the default data view will not be unset when the resource is destroyed. The existing default data view will remain unchanged.", + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + }, + }, + } +} diff --git a/internal/kibana/default_data_view/update.go b/internal/kibana/default_data_view/update.go new file mode 100644 index 000000000..203700d30 --- /dev/null +++ b/internal/kibana/default_data_view/update.go @@ -0,0 +1,46 @@ +package default_data_view + +import ( + "context" + "fmt" + + "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" + "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +func (r *DefaultDataViewResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan defaultDataViewModel + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + client, err := r.client.GetKibanaOapiClient() + if err != nil { + resp.Diagnostics.AddError("unable to get kibana client", err.Error()) + return + } + + dataViewID := plan.DataViewID.ValueString() + force := plan.Force.ValueBool() + + setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ + DataViewId: &dataViewID, + Force: &force, + } + + diags = kibana_oapi.SetDefaultDataView(ctx, client, setReq) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + // Update the ID to reflect the new data view ID + plan.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", dataViewID)) + + diags = resp.State.Set(ctx, plan) + resp.Diagnostics.Append(diags...) +} diff --git a/provider/plugin_framework.go b/provider/plugin_framework.go index 47a51ea2c..5c95d3792 100644 --- a/provider/plugin_framework.go +++ b/provider/plugin_framework.go @@ -23,6 +23,7 @@ import ( "github.com/elastic/terraform-provider-elasticstack/internal/fleet/server_host" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/connectors" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/data_view" + "github.com/elastic/terraform-provider-elasticstack/internal/kibana/default_data_view" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/export_saved_objects" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/import_saved_objects" "github.com/elastic/terraform-provider-elasticstack/internal/kibana/maintenance_window" @@ -104,6 +105,7 @@ func (p *Provider) Resources(ctx context.Context) []func() resource.Resource { agent_configuration.NewAgentConfigurationResource, func() resource.Resource { return &import_saved_objects.Resource{} }, data_view.NewResource, + default_data_view.NewResource, func() resource.Resource { return ¶meter.Resource{} }, func() resource.Resource { return &private_location.Resource{} }, func() resource.Resource { return &index.Resource{} }, From 31bdf5c3493fff1d4e91ea045ba6d574360cb453 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Oct 2025 22:45:52 +0000 Subject: [PATCH 3/6] Fix ID consistency and generate documentation Co-authored-by: tobio <444668+tobio@users.noreply.github.com> --- docs/resources/kibana_default_data_view.md | 29 +++++++++++++++++++++ internal/kibana/default_data_view/create.go | 5 ++-- internal/kibana/default_data_view/read.go | 6 +++-- internal/kibana/default_data_view/update.go | 5 ++-- 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 docs/resources/kibana_default_data_view.md diff --git a/docs/resources/kibana_default_data_view.md b/docs/resources/kibana_default_data_view.md new file mode 100644 index 000000000..45efbc551 --- /dev/null +++ b/docs/resources/kibana_default_data_view.md @@ -0,0 +1,29 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "elasticstack_kibana_default_data_view Resource - terraform-provider-elasticstack" +subcategory: "Kibana" +description: |- + Manages the default Kibana data view. See the Kibana Data Views API documentation https://www.elastic.co/docs/api/doc/kibana/v8/operation/operation-setdefaultdatailviewdefault for more information. +--- + +# elasticstack_kibana_default_data_view (Resource) + +Manages the default Kibana data view. See the [Kibana Data Views API documentation](https://www.elastic.co/docs/api/doc/kibana/v8/operation/operation-setdefaultdatailviewdefault) for more information. + + + + +## Schema + +### Required + +- `data_view_id` (String) The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Use `null` to unset the default data view. + +### Optional + +- `force` (Boolean) Update an existing default data view identifier. If set to false and a default data view already exists, the operation will fail. +- `skip_delete` (Boolean) If set to true, the default data view will not be unset when the resource is destroyed. The existing default data view will remain unchanged. + +### Read-Only + +- `id` (String) Internal identifier of the resource. diff --git a/internal/kibana/default_data_view/create.go b/internal/kibana/default_data_view/create.go index 8991854b0..20c946f86 100644 --- a/internal/kibana/default_data_view/create.go +++ b/internal/kibana/default_data_view/create.go @@ -2,7 +2,6 @@ package default_data_view import ( "context" - "fmt" "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" @@ -38,8 +37,8 @@ func (r *DefaultDataViewResource) Create(ctx context.Context, req resource.Creat return } - // Set the ID to the data view ID for state tracking - plan.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", dataViewID)) + // Set a static ID since there's only one default data view setting + plan.ID = types.StringValue("default") diags = resp.State.Set(ctx, plan) resp.Diagnostics.Append(diags...) diff --git a/internal/kibana/default_data_view/read.go b/internal/kibana/default_data_view/read.go index 42de74fd8..6e4e3d579 100644 --- a/internal/kibana/default_data_view/read.go +++ b/internal/kibana/default_data_view/read.go @@ -2,7 +2,6 @@ package default_data_view import ( "context" - "fmt" "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" "github.com/hashicorp/terraform-plugin-framework/resource" @@ -37,7 +36,10 @@ func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadReq // Update state with current default data view state.DataViewID = types.StringValue(*defaultDataViewID) - state.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", *defaultDataViewID)) + // Keep the ID as "default" - it should remain static + if state.ID.IsNull() || state.ID.IsUnknown() { + state.ID = types.StringValue("default") + } diags = resp.State.Set(ctx, state) resp.Diagnostics.Append(diags...) diff --git a/internal/kibana/default_data_view/update.go b/internal/kibana/default_data_view/update.go index 203700d30..2472b6837 100644 --- a/internal/kibana/default_data_view/update.go +++ b/internal/kibana/default_data_view/update.go @@ -2,7 +2,6 @@ package default_data_view import ( "context" - "fmt" "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" @@ -38,8 +37,8 @@ func (r *DefaultDataViewResource) Update(ctx context.Context, req resource.Updat return } - // Update the ID to reflect the new data view ID - plan.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", dataViewID)) + // Keep the ID as "default" - it should remain static + plan.ID = types.StringValue("default") diags = resp.State.Set(ctx, plan) resp.Diagnostics.Append(diags...) From 8862467b52560a472b8a3b46ca0ed235820ff10f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 19 Oct 2025 22:49:35 +0000 Subject: [PATCH 4/6] Add linting fixes, example, and final documentation Co-authored-by: tobio <444668+tobio@users.noreply.github.com> --- docs/resources/kibana_default_data_view.md | 24 ++++++++++++++++++- .../resource.tf | 19 +++++++++++++++ internal/kibana/default_data_view/models.go | 8 +++---- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 examples/resources/elasticstack_kibana_default_data_view/resource.tf diff --git a/docs/resources/kibana_default_data_view.md b/docs/resources/kibana_default_data_view.md index 45efbc551..9cd87f4a6 100644 --- a/docs/resources/kibana_default_data_view.md +++ b/docs/resources/kibana_default_data_view.md @@ -10,7 +10,29 @@ description: |- Manages the default Kibana data view. See the [Kibana Data Views API documentation](https://www.elastic.co/docs/api/doc/kibana/v8/operation/operation-setdefaultdatailviewdefault) for more information. - +## Example Usage + +```terraform +resource "elasticstack_elasticsearch_index" "my_index" { + name = "my-index-000001" + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "my_data_view" { + data_view = { + title = "my-index-*" + name = "My Index Data View" + } + + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "default" { + data_view_id = elasticstack_kibana_data_view.my_data_view.data_view.id + force = true + skip_delete = false +} +``` ## Schema diff --git a/examples/resources/elasticstack_kibana_default_data_view/resource.tf b/examples/resources/elasticstack_kibana_default_data_view/resource.tf new file mode 100644 index 000000000..8b8f3fd8c --- /dev/null +++ b/examples/resources/elasticstack_kibana_default_data_view/resource.tf @@ -0,0 +1,19 @@ +resource "elasticstack_elasticsearch_index" "my_index" { + name = "my-index-000001" + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "my_data_view" { + data_view = { + title = "my-index-*" + name = "My Index Data View" + } + + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "default" { + data_view_id = elasticstack_kibana_data_view.my_data_view.data_view.id + force = true + skip_delete = false +} diff --git a/internal/kibana/default_data_view/models.go b/internal/kibana/default_data_view/models.go index 8bc5743b1..b42103ce2 100644 --- a/internal/kibana/default_data_view/models.go +++ b/internal/kibana/default_data_view/models.go @@ -5,8 +5,8 @@ import ( ) type defaultDataViewModel struct { - ID types.String `tfsdk:"id"` - DataViewID types.String `tfsdk:"data_view_id"` - Force types.Bool `tfsdk:"force"` - SkipDelete types.Bool `tfsdk:"skip_delete"` + ID types.String `tfsdk:"id"` + DataViewID types.String `tfsdk:"data_view_id"` + Force types.Bool `tfsdk:"force"` + SkipDelete types.Bool `tfsdk:"skip_delete"` } From 9b64020e5230723b7093909cad5bddbbed83756a Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Mon, 20 Oct 2025 13:51:05 +1100 Subject: [PATCH 5/6] Make default data view API space aware --- docs/resources/kibana_default_data_view.md | 1 + generated/kbapi/kibana.gen.go | 1041 ++++++++++++----- generated/kbapi/transform_schema.go | 1 + internal/clients/kibana_oapi/data_views.go | 8 +- internal/kibana/default_data_view/acc_test.go | 66 +- internal/kibana/default_data_view/create.go | 42 +- internal/kibana/default_data_view/delete.go | 14 +- internal/kibana/default_data_view/models.go | 1 + internal/kibana/default_data_view/read.go | 11 +- internal/kibana/default_data_view/schema.go | 12 +- internal/kibana/default_data_view/update.go | 36 +- 11 files changed, 852 insertions(+), 381 deletions(-) diff --git a/docs/resources/kibana_default_data_view.md b/docs/resources/kibana_default_data_view.md index 9cd87f4a6..9c8cf8429 100644 --- a/docs/resources/kibana_default_data_view.md +++ b/docs/resources/kibana_default_data_view.md @@ -45,6 +45,7 @@ resource "elasticstack_kibana_default_data_view" "default" { - `force` (Boolean) Update an existing default data view identifier. If set to false and a default data view already exists, the operation will fail. - `skip_delete` (Boolean) If set to true, the default data view will not be unset when the resource is destroyed. The existing default data view will remain unchanged. +- `space_id` (String) The Kibana space ID to set the default data view in. Defaults to `default`. ### Read-Only diff --git a/generated/kbapi/kibana.gen.go b/generated/kbapi/kibana.gen.go index 5031ad980..de3725f4f 100644 --- a/generated/kbapi/kibana.gen.go +++ b/generated/kbapi/kibana.gen.go @@ -25912,15 +25912,6 @@ type UpdateRuntimeFieldDefaultJSONBody struct { RuntimeField map[string]interface{} `json:"runtimeField"` } -// SetDefaultDatailViewDefaultJSONBody defines parameters for SetDefaultDatailViewDefault. -type SetDefaultDatailViewDefaultJSONBody struct { - // DataViewId The data view identifier. NOTE: The API does not validate whether it is a valid identifier. Use `null` to unset the default data view. - DataViewId *string `json:"data_view_id,omitempty"` - - // Force Update an existing default data view identifier. - Force *bool `json:"force,omitempty"` -} - // DeleteRuleParams defines parameters for DeleteRule. type DeleteRuleParams struct { // Id The rule's `id` value. @@ -28461,6 +28452,39 @@ type GetFleetAgentsActionStatusParams struct { ErrorSize *float32 `form:"errorSize,omitempty" json:"errorSize,omitempty"` } +// PostFleetAgentsBulkMigrateJSONBody defines parameters for PostFleetAgentsBulkMigrate. +type PostFleetAgentsBulkMigrateJSONBody struct { + Agents PostFleetAgentsBulkMigrateJSONBody_Agents `json:"agents"` + BatchSize *float32 `json:"batchSize,omitempty"` + EnrollmentToken string `json:"enrollment_token"` + Settings *struct { + CaSha256 *string `json:"ca_sha256,omitempty"` + CertificateAuthorities *string `json:"certificate_authorities,omitempty"` + ElasticAgentCert *string `json:"elastic_agent_cert,omitempty"` + ElasticAgentCertKey *string `json:"elastic_agent_cert_key,omitempty"` + ElasticAgentCertKeyPassphrase *string `json:"elastic_agent_cert_key_passphrase,omitempty"` + Headers *map[string]string `json:"headers,omitempty"` + Insecure *bool `json:"insecure,omitempty"` + ProxyDisabled *bool `json:"proxy_disabled,omitempty"` + ProxyHeaders *map[string]string `json:"proxy_headers,omitempty"` + ProxyUrl *string `json:"proxy_url,omitempty"` + Staging *string `json:"staging,omitempty"` + Tags *[]string `json:"tags,omitempty"` + } `json:"settings,omitempty"` + Uri string `json:"uri"` +} + +// PostFleetAgentsBulkMigrateJSONBodyAgents0 defines parameters for PostFleetAgentsBulkMigrate. +type PostFleetAgentsBulkMigrateJSONBodyAgents0 = []string + +// PostFleetAgentsBulkMigrateJSONBodyAgents1 defines parameters for PostFleetAgentsBulkMigrate. +type PostFleetAgentsBulkMigrateJSONBodyAgents1 = string + +// PostFleetAgentsBulkMigrateJSONBody_Agents defines parameters for PostFleetAgentsBulkMigrate. +type PostFleetAgentsBulkMigrateJSONBody_Agents struct { + union json.RawMessage +} + // PostFleetAgentsBulkReassignJSONBody defines parameters for PostFleetAgentsBulkReassign. type PostFleetAgentsBulkReassignJSONBody struct { Agents PostFleetAgentsBulkReassignJSONBody_Agents `json:"agents"` @@ -28622,6 +28646,27 @@ type PostFleetAgentsAgentidActionsJSONBody_Action struct { union json.RawMessage } +// PostFleetAgentsAgentidMigrateJSONBody defines parameters for PostFleetAgentsAgentidMigrate. +type PostFleetAgentsAgentidMigrateJSONBody struct { + EnrollmentToken string `json:"enrollment_token"` + Settings *struct { + CaSha256 *string `json:"ca_sha256,omitempty"` + CertificateAuthorities *string `json:"certificate_authorities,omitempty"` + ElasticAgentCert *string `json:"elastic_agent_cert,omitempty"` + ElasticAgentCertKey *string `json:"elastic_agent_cert_key,omitempty"` + ElasticAgentCertKeyPassphrase *string `json:"elastic_agent_cert_key_passphrase,omitempty"` + Headers *map[string]string `json:"headers,omitempty"` + Insecure *bool `json:"insecure,omitempty"` + ProxyDisabled *bool `json:"proxy_disabled,omitempty"` + ProxyHeaders *map[string]string `json:"proxy_headers,omitempty"` + ProxyUrl *string `json:"proxy_url,omitempty"` + ReplaceToken *string `json:"replace_token,omitempty"` + Staging *string `json:"staging,omitempty"` + Tags *[]string `json:"tags,omitempty"` + } `json:"settings,omitempty"` + Uri string `json:"uri"` +} + // PostFleetAgentsAgentidReassignJSONBody defines parameters for PostFleetAgentsAgentidReassign. type PostFleetAgentsAgentidReassignJSONBody struct { PolicyId string `json:"policy_id"` @@ -41372,6 +41417,15 @@ type PutActionsConnectorIdJSONBody struct { Secrets *UpdateConnectorSecrets `json:"secrets,omitempty"` } +// SetDefaultDatailViewDefaultJSONBody defines parameters for SetDefaultDatailViewDefault. +type SetDefaultDatailViewDefaultJSONBody struct { + // DataViewId The data view identifier. NOTE: The API does not validate whether it is a valid identifier. Use `null` to unset the default data view. + DataViewId *string `json:"data_view_id,omitempty"` + + // Force Update an existing default data view identifier. + Force *bool `json:"force,omitempty"` +} + // PostMaintenanceWindowJSONBody defines parameters for PostMaintenanceWindow. type PostMaintenanceWindowJSONBody struct { // Enabled Whether the current maintenance window is enabled. Disabled maintenance windows do not suppress notifications. @@ -41642,9 +41696,6 @@ type CreateUpdateRuntimeFieldDefaultJSONRequestBody CreateUpdateRuntimeFieldDefa // UpdateRuntimeFieldDefaultJSONRequestBody defines body for UpdateRuntimeFieldDefault for application/json ContentType. type UpdateRuntimeFieldDefaultJSONRequestBody UpdateRuntimeFieldDefaultJSONBody -// SetDefaultDatailViewDefaultJSONRequestBody defines body for SetDefaultDatailViewDefault for application/json ContentType. -type SetDefaultDatailViewDefaultJSONRequestBody SetDefaultDatailViewDefaultJSONBody - // SwapDataViewsDefaultJSONRequestBody defines body for SwapDataViewsDefault for application/json ContentType. type SwapDataViewsDefaultJSONRequestBody = DataViewsSwapDataViewRequestObject @@ -41801,6 +41852,9 @@ type PostFleetAgentPoliciesAgentpolicyidCopyJSONRequestBody PostFleetAgentPolici // PostFleetAgentsJSONRequestBody defines body for PostFleetAgents for application/json ContentType. type PostFleetAgentsJSONRequestBody PostFleetAgentsJSONBody +// PostFleetAgentsBulkMigrateJSONRequestBody defines body for PostFleetAgentsBulkMigrate for application/json ContentType. +type PostFleetAgentsBulkMigrateJSONRequestBody PostFleetAgentsBulkMigrateJSONBody + // PostFleetAgentsBulkReassignJSONRequestBody defines body for PostFleetAgentsBulkReassign for application/json ContentType. type PostFleetAgentsBulkReassignJSONRequestBody PostFleetAgentsBulkReassignJSONBody @@ -41822,6 +41876,9 @@ type PutFleetAgentsAgentidJSONRequestBody PutFleetAgentsAgentidJSONBody // PostFleetAgentsAgentidActionsJSONRequestBody defines body for PostFleetAgentsAgentidActions for application/json ContentType. type PostFleetAgentsAgentidActionsJSONRequestBody PostFleetAgentsAgentidActionsJSONBody +// PostFleetAgentsAgentidMigrateJSONRequestBody defines body for PostFleetAgentsAgentidMigrate for application/json ContentType. +type PostFleetAgentsAgentidMigrateJSONRequestBody PostFleetAgentsAgentidMigrateJSONBody + // PostFleetAgentsAgentidReassignJSONRequestBody defines body for PostFleetAgentsAgentidReassign for application/json ContentType. type PostFleetAgentsAgentidReassignJSONRequestBody PostFleetAgentsAgentidReassignJSONBody @@ -42227,6 +42284,9 @@ type CreateDataViewDefaultwJSONRequestBody = DataViewsCreateDataViewRequestObjec // UpdateDataViewDefaultJSONRequestBody defines body for UpdateDataViewDefault for application/json ContentType. type UpdateDataViewDefaultJSONRequestBody = DataViewsUpdateDataViewRequestObject +// SetDefaultDatailViewDefaultJSONRequestBody defines body for SetDefaultDatailViewDefault for application/json ContentType. +type SetDefaultDatailViewDefaultJSONRequestBody SetDefaultDatailViewDefaultJSONBody + // PostMaintenanceWindowJSONRequestBody defines body for PostMaintenanceWindow for application/json ContentType. type PostMaintenanceWindowJSONRequestBody PostMaintenanceWindowJSONBody @@ -54709,7 +54769,7 @@ func (t SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item) AsSLO // FromSLOsTimesliceMetricBasicMetricWithField overwrites any union data inside the SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item as the provided SLOsTimesliceMetricBasicMetricWithField func (t *SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item) FromSLOsTimesliceMetricBasicMetricWithField(v SLOsTimesliceMetricBasicMetricWithField) error { - v.Aggregation = "std_deviation" + v.Aggregation = "avg" b, err := json.Marshal(v) t.union = b return err @@ -54717,7 +54777,7 @@ func (t *SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item) From // MergeSLOsTimesliceMetricBasicMetricWithField performs a merge with any union data inside the SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item, using the provided SLOsTimesliceMetricBasicMetricWithField func (t *SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item) MergeSLOsTimesliceMetricBasicMetricWithField(v SLOsTimesliceMetricBasicMetricWithField) error { - v.Aggregation = "std_deviation" + v.Aggregation = "avg" b, err := json.Marshal(v) if err != nil { return err @@ -54798,12 +54858,12 @@ func (t SLOsIndicatorPropertiesTimesliceMetric_Params_Metric_Metrics_Item) Value return nil, err } switch discriminator { + case "avg": + return t.AsSLOsTimesliceMetricBasicMetricWithField() case "doc_count": return t.AsSLOsTimesliceMetricDocCountMetric() case "percentile": return t.AsSLOsTimesliceMetricPercentileMetric() - case "std_deviation": - return t.AsSLOsTimesliceMetricBasicMetricWithField() default: return nil, errors.New("unknown discriminator value: " + discriminator) } @@ -68062,14 +68122,6 @@ type ClientInterface interface { UpdateRuntimeFieldDefault(ctx context.Context, viewId DataViewsViewId, fieldName DataViewsFieldName, body UpdateRuntimeFieldDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - // GetDefaultDataViewDefault request - GetDefaultDataViewDefault(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) - - // SetDefaultDatailViewDefaultWithBody request with any body - SetDefaultDatailViewDefaultWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - - SetDefaultDatailViewDefault(ctx context.Context, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) - // SwapDataViewsDefaultWithBody request with any body SwapDataViewsDefaultWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -68529,6 +68581,11 @@ type ClientInterface interface { // GetFleetAgentsAvailableVersions request GetFleetAgentsAvailableVersions(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostFleetAgentsBulkMigrateWithBody request with any body + PostFleetAgentsBulkMigrateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostFleetAgentsBulkMigrate(ctx context.Context, body PostFleetAgentsBulkMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostFleetAgentsBulkReassignWithBody request with any body PostFleetAgentsBulkReassignWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -68585,6 +68642,11 @@ type ClientInterface interface { PostFleetAgentsAgentidActions(ctx context.Context, agentId string, body PostFleetAgentsAgentidActionsJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostFleetAgentsAgentidMigrateWithBody request with any body + PostFleetAgentsAgentidMigrateWithBody(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + PostFleetAgentsAgentidMigrate(ctx context.Context, agentId string, body PostFleetAgentsAgentidMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostFleetAgentsAgentidReassignWithBody request with any body PostFleetAgentsAgentidReassignWithBody(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -69624,6 +69686,14 @@ type ClientInterface interface { UpdateDataViewDefault(ctx context.Context, spaceId SpaceId, viewId DataViewsViewId, body UpdateDataViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // GetDefaultDataViewDefault request + GetDefaultDataViewDefault(ctx context.Context, spaceId SpaceId, reqEditors ...RequestEditorFn) (*http.Response, error) + + // SetDefaultDatailViewDefaultWithBody request with any body + SetDefaultDatailViewDefaultWithBody(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + SetDefaultDatailViewDefault(ctx context.Context, spaceId SpaceId, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostMaintenanceWindowWithBody request with any body PostMaintenanceWindowWithBody(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -71298,42 +71368,6 @@ func (c *Client) UpdateRuntimeFieldDefault(ctx context.Context, viewId DataViews return c.Client.Do(req) } -func (c *Client) GetDefaultDataViewDefault(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewGetDefaultDataViewDefaultRequest(c.Server) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - -func (c *Client) SetDefaultDatailViewDefaultWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewSetDefaultDatailViewDefaultRequestWithBody(c.Server, contentType, body) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - -func (c *Client) SetDefaultDatailViewDefault(ctx context.Context, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewSetDefaultDatailViewDefaultRequest(c.Server, body) - if err != nil { - return nil, err - } - req = req.WithContext(ctx) - if err := c.applyEditors(ctx, req, reqEditors); err != nil { - return nil, err - } - return c.Client.Do(req) -} - func (c *Client) SwapDataViewsDefaultWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewSwapDataViewsDefaultRequestWithBody(c.Server, contentType, body) if err != nil { @@ -73362,6 +73396,30 @@ func (c *Client) GetFleetAgentsAvailableVersions(ctx context.Context, reqEditors return c.Client.Do(req) } +func (c *Client) PostFleetAgentsBulkMigrateWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostFleetAgentsBulkMigrateRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostFleetAgentsBulkMigrate(ctx context.Context, body PostFleetAgentsBulkMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostFleetAgentsBulkMigrateRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) PostFleetAgentsBulkReassignWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPostFleetAgentsBulkReassignRequestWithBody(c.Server, contentType, body) if err != nil { @@ -73614,6 +73672,30 @@ func (c *Client) PostFleetAgentsAgentidActions(ctx context.Context, agentId stri return c.Client.Do(req) } +func (c *Client) PostFleetAgentsAgentidMigrateWithBody(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostFleetAgentsAgentidMigrateRequestWithBody(c.Server, agentId, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostFleetAgentsAgentidMigrate(ctx context.Context, agentId string, body PostFleetAgentsAgentidMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostFleetAgentsAgentidMigrateRequest(c.Server, agentId, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) PostFleetAgentsAgentidReassignWithBody(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPostFleetAgentsAgentidReassignRequestWithBody(c.Server, agentId, contentType, body) if err != nil { @@ -78294,6 +78376,42 @@ func (c *Client) UpdateDataViewDefault(ctx context.Context, spaceId SpaceId, vie return c.Client.Do(req) } +func (c *Client) GetDefaultDataViewDefault(ctx context.Context, spaceId SpaceId, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetDefaultDataViewDefaultRequest(c.Server, spaceId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) SetDefaultDatailViewDefaultWithBody(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDefaultDatailViewDefaultRequestWithBody(c.Server, spaceId, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) SetDefaultDatailViewDefault(ctx context.Context, spaceId SpaceId, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewSetDefaultDatailViewDefaultRequest(c.Server, spaceId, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) PostMaintenanceWindowWithBody(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewPostMaintenanceWindowRequestWithBody(c.Server, spaceId, contentType, body) if err != nil { @@ -83778,73 +83896,6 @@ func NewUpdateRuntimeFieldDefaultRequestWithBody(server string, viewId DataViews return req, nil } -// NewGetDefaultDataViewDefaultRequest generates requests for GetDefaultDataViewDefault -func NewGetDefaultDataViewDefaultRequest(server string) (*http.Request, error) { - var err error - - serverURL, err := url.Parse(server) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("/api/data_views/default") - if operationPath[0] == '/' { - operationPath = "." + operationPath - } - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("GET", queryURL.String(), nil) - if err != nil { - return nil, err - } - - return req, nil -} - -// NewSetDefaultDatailViewDefaultRequest calls the generic SetDefaultDatailViewDefault builder with application/json body -func NewSetDefaultDatailViewDefaultRequest(server string, body SetDefaultDatailViewDefaultJSONRequestBody) (*http.Request, error) { - var bodyReader io.Reader - buf, err := json.Marshal(body) - if err != nil { - return nil, err - } - bodyReader = bytes.NewReader(buf) - return NewSetDefaultDatailViewDefaultRequestWithBody(server, "application/json", bodyReader) -} - -// NewSetDefaultDatailViewDefaultRequestWithBody generates requests for SetDefaultDatailViewDefault with any type of body -func NewSetDefaultDatailViewDefaultRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { - var err error - - serverURL, err := url.Parse(server) - if err != nil { - return nil, err - } - - operationPath := fmt.Sprintf("/api/data_views/default") - if operationPath[0] == '/' { - operationPath = "." + operationPath - } - - queryURL, err := serverURL.Parse(operationPath) - if err != nil { - return nil, err - } - - req, err := http.NewRequest("POST", queryURL.String(), body) - if err != nil { - return nil, err - } - - req.Header.Add("Content-Type", contentType) - - return req, nil -} - // NewSwapDataViewsDefaultRequest calls the generic SwapDataViewsDefault builder with application/json body func NewSwapDataViewsDefaultRequest(server string, body SwapDataViewsDefaultJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -90500,6 +90551,46 @@ func NewGetFleetAgentsAvailableVersionsRequest(server string) (*http.Request, er return req, nil } +// NewPostFleetAgentsBulkMigrateRequest calls the generic PostFleetAgentsBulkMigrate builder with application/json body +func NewPostFleetAgentsBulkMigrateRequest(server string, body PostFleetAgentsBulkMigrateJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostFleetAgentsBulkMigrateRequestWithBody(server, "application/json", bodyReader) +} + +// NewPostFleetAgentsBulkMigrateRequestWithBody generates requests for PostFleetAgentsBulkMigrate with any type of body +func NewPostFleetAgentsBulkMigrateRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/fleet/agents/bulk_migrate") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewPostFleetAgentsBulkReassignRequest calls the generic PostFleetAgentsBulkReassign builder with application/json body func NewPostFleetAgentsBulkReassignRequest(server string, body PostFleetAgentsBulkReassignJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -91078,6 +91169,53 @@ func NewPostFleetAgentsAgentidActionsRequestWithBody(server string, agentId stri return req, nil } +// NewPostFleetAgentsAgentidMigrateRequest calls the generic PostFleetAgentsAgentidMigrate builder with application/json body +func NewPostFleetAgentsAgentidMigrateRequest(server string, agentId string, body PostFleetAgentsAgentidMigrateJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewPostFleetAgentsAgentidMigrateRequestWithBody(server, agentId, "application/json", bodyReader) +} + +// NewPostFleetAgentsAgentidMigrateRequestWithBody generates requests for PostFleetAgentsAgentidMigrate with any type of body +func NewPostFleetAgentsAgentidMigrateRequestWithBody(server string, agentId string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "agentId", runtime.ParamLocationPath, agentId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/fleet/agents/%s/migrate", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewPostFleetAgentsAgentidReassignRequest calls the generic PostFleetAgentsAgentidReassign builder with application/json body func NewPostFleetAgentsAgentidReassignRequest(server string, agentId string, body PostFleetAgentsAgentidReassignJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader @@ -104628,7 +104766,48 @@ func NewDeleteDataViewDefaultRequest(server string, spaceId SpaceId, viewId Data return nil, err } - req, err := http.NewRequest("DELETE", queryURL.String(), nil) + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetDataViewDefaultRequest generates requests for GetDataViewDefault +func NewGetDataViewDefaultRequest(server string, spaceId SpaceId, viewId DataViewsViewId) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "spaceId", runtime.ParamLocationPath, spaceId) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "viewId", runtime.ParamLocationPath, viewId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/s/%s/api/data_views/data_view/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err } @@ -104636,8 +104815,19 @@ func NewDeleteDataViewDefaultRequest(server string, spaceId SpaceId, viewId Data return req, nil } -// NewGetDataViewDefaultRequest generates requests for GetDataViewDefault -func NewGetDataViewDefaultRequest(server string, spaceId SpaceId, viewId DataViewsViewId) (*http.Request, error) { +// NewUpdateDataViewDefaultRequest calls the generic UpdateDataViewDefault builder with application/json body +func NewUpdateDataViewDefaultRequest(server string, spaceId SpaceId, viewId DataViewsViewId, body UpdateDataViewDefaultJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewUpdateDataViewDefaultRequestWithBody(server, spaceId, viewId, "application/json", bodyReader) +} + +// NewUpdateDataViewDefaultRequestWithBody generates requests for UpdateDataViewDefault with any type of body +func NewUpdateDataViewDefaultRequestWithBody(server string, spaceId SpaceId, viewId DataViewsViewId, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -104669,6 +104859,42 @@ func NewGetDataViewDefaultRequest(server string, spaceId SpaceId, viewId DataVie return nil, err } + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewGetDefaultDataViewDefaultRequest generates requests for GetDefaultDataViewDefault +func NewGetDefaultDataViewDefaultRequest(server string, spaceId SpaceId) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "spaceId", runtime.ParamLocationPath, spaceId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/s/%s/api/data_views/default", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + req, err := http.NewRequest("GET", queryURL.String(), nil) if err != nil { return nil, err @@ -104677,19 +104903,19 @@ func NewGetDataViewDefaultRequest(server string, spaceId SpaceId, viewId DataVie return req, nil } -// NewUpdateDataViewDefaultRequest calls the generic UpdateDataViewDefault builder with application/json body -func NewUpdateDataViewDefaultRequest(server string, spaceId SpaceId, viewId DataViewsViewId, body UpdateDataViewDefaultJSONRequestBody) (*http.Request, error) { +// NewSetDefaultDatailViewDefaultRequest calls the generic SetDefaultDatailViewDefault builder with application/json body +func NewSetDefaultDatailViewDefaultRequest(server string, spaceId SpaceId, body SetDefaultDatailViewDefaultJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) - return NewUpdateDataViewDefaultRequestWithBody(server, spaceId, viewId, "application/json", bodyReader) + return NewSetDefaultDatailViewDefaultRequestWithBody(server, spaceId, "application/json", bodyReader) } -// NewUpdateDataViewDefaultRequestWithBody generates requests for UpdateDataViewDefault with any type of body -func NewUpdateDataViewDefaultRequestWithBody(server string, spaceId SpaceId, viewId DataViewsViewId, contentType string, body io.Reader) (*http.Request, error) { +// NewSetDefaultDatailViewDefaultRequestWithBody generates requests for SetDefaultDatailViewDefault with any type of body +func NewSetDefaultDatailViewDefaultRequestWithBody(server string, spaceId SpaceId, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -104699,19 +104925,12 @@ func NewUpdateDataViewDefaultRequestWithBody(server string, spaceId SpaceId, vie return nil, err } - var pathParam1 string - - pathParam1, err = runtime.StyleParamWithLocation("simple", false, "viewId", runtime.ParamLocationPath, viewId) - if err != nil { - return nil, err - } - serverURL, err := url.Parse(server) if err != nil { return nil, err } - operationPath := fmt.Sprintf("/s/%s/api/data_views/data_view/%s", pathParam0, pathParam1) + operationPath := fmt.Sprintf("/s/%s/api/data_views/default", pathParam0) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -106120,14 +106339,6 @@ type ClientWithResponsesInterface interface { UpdateRuntimeFieldDefaultWithResponse(ctx context.Context, viewId DataViewsViewId, fieldName DataViewsFieldName, body UpdateRuntimeFieldDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateRuntimeFieldDefaultResponse, error) - // GetDefaultDataViewDefaultWithResponse request - GetDefaultDataViewDefaultWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetDefaultDataViewDefaultResponse, error) - - // SetDefaultDatailViewDefaultWithBodyWithResponse request with any body - SetDefaultDatailViewDefaultWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) - - SetDefaultDatailViewDefaultWithResponse(ctx context.Context, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) - // SwapDataViewsDefaultWithBodyWithResponse request with any body SwapDataViewsDefaultWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SwapDataViewsDefaultResponse, error) @@ -106587,6 +106798,11 @@ type ClientWithResponsesInterface interface { // GetFleetAgentsAvailableVersionsWithResponse request GetFleetAgentsAvailableVersionsWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetFleetAgentsAvailableVersionsResponse, error) + // PostFleetAgentsBulkMigrateWithBodyWithResponse request with any body + PostFleetAgentsBulkMigrateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsBulkMigrateResponse, error) + + PostFleetAgentsBulkMigrateWithResponse(ctx context.Context, body PostFleetAgentsBulkMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*PostFleetAgentsBulkMigrateResponse, error) + // PostFleetAgentsBulkReassignWithBodyWithResponse request with any body PostFleetAgentsBulkReassignWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsBulkReassignResponse, error) @@ -106643,6 +106859,11 @@ type ClientWithResponsesInterface interface { PostFleetAgentsAgentidActionsWithResponse(ctx context.Context, agentId string, body PostFleetAgentsAgentidActionsJSONRequestBody, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidActionsResponse, error) + // PostFleetAgentsAgentidMigrateWithBodyWithResponse request with any body + PostFleetAgentsAgentidMigrateWithBodyWithResponse(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidMigrateResponse, error) + + PostFleetAgentsAgentidMigrateWithResponse(ctx context.Context, agentId string, body PostFleetAgentsAgentidMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidMigrateResponse, error) + // PostFleetAgentsAgentidReassignWithBodyWithResponse request with any body PostFleetAgentsAgentidReassignWithBodyWithResponse(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidReassignResponse, error) @@ -107682,6 +107903,14 @@ type ClientWithResponsesInterface interface { UpdateDataViewDefaultWithResponse(ctx context.Context, spaceId SpaceId, viewId DataViewsViewId, body UpdateDataViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateDataViewDefaultResponse, error) + // GetDefaultDataViewDefaultWithResponse request + GetDefaultDataViewDefaultWithResponse(ctx context.Context, spaceId SpaceId, reqEditors ...RequestEditorFn) (*GetDefaultDataViewDefaultResponse, error) + + // SetDefaultDatailViewDefaultWithBodyWithResponse request with any body + SetDefaultDatailViewDefaultWithBodyWithResponse(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) + + SetDefaultDatailViewDefaultWithResponse(ctx context.Context, spaceId SpaceId, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) + // PostMaintenanceWindowWithBodyWithResponse request with any body PostMaintenanceWindowWithBodyWithResponse(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostMaintenanceWindowResponse, error) @@ -111898,56 +112127,6 @@ func (r UpdateRuntimeFieldDefaultResponse) StatusCode() int { return 0 } -type GetDefaultDataViewDefaultResponse struct { - Body []byte - HTTPResponse *http.Response - JSON200 *struct { - DataViewId *string `json:"data_view_id,omitempty"` - } - JSON400 *DataViews400Response -} - -// Status returns HTTPResponse.Status -func (r GetDefaultDataViewDefaultResponse) Status() string { - if r.HTTPResponse != nil { - return r.HTTPResponse.Status - } - return http.StatusText(0) -} - -// StatusCode returns HTTPResponse.StatusCode -func (r GetDefaultDataViewDefaultResponse) StatusCode() int { - if r.HTTPResponse != nil { - return r.HTTPResponse.StatusCode - } - return 0 -} - -type SetDefaultDatailViewDefaultResponse struct { - Body []byte - HTTPResponse *http.Response - JSON200 *struct { - Acknowledged *bool `json:"acknowledged,omitempty"` - } - JSON400 *DataViews400Response -} - -// Status returns HTTPResponse.Status -func (r SetDefaultDatailViewDefaultResponse) Status() string { - if r.HTTPResponse != nil { - return r.HTTPResponse.Status - } - return http.StatusText(0) -} - -// StatusCode returns HTTPResponse.StatusCode -func (r SetDefaultDatailViewDefaultResponse) StatusCode() int { - if r.HTTPResponse != nil { - return r.HTTPResponse.StatusCode - } - return 0 -} - type SwapDataViewsDefaultResponse struct { Body []byte HTTPResponse *http.Response @@ -113063,8 +113242,21 @@ func (r EndpointGetActionsDetailsResponse) StatusCode() int { type EndpointFileInfoResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *SecurityEndpointManagementAPISuccessResponse + JSON200 *struct { + Data *struct { + ActionId *string `json:"actionId,omitempty"` + AgentId *string `json:"agentId,omitempty"` + AgentType *string `json:"agentType,omitempty"` + Created *time.Time `json:"created,omitempty"` + Id *string `json:"id,omitempty"` + MimeType *string `json:"mimeType,omitempty"` + Name *string `json:"name,omitempty"` + Size *float32 `json:"size,omitempty"` + Status *EndpointFileInfo200DataStatus `json:"status,omitempty"` + } `json:"data,omitempty"` + } } +type EndpointFileInfo200DataStatus string // Status returns HTTPResponse.Status func (r EndpointFileInfoResponse) Status() string { @@ -113085,7 +113277,6 @@ func (r EndpointFileInfoResponse) StatusCode() int { type EndpointFileDownloadResponse struct { Body []byte HTTPResponse *http.Response - JSON200 *SecurityEndpointManagementAPISuccessResponse } // Status returns HTTPResponse.Status @@ -116398,6 +116589,37 @@ func (r GetFleetAgentsAvailableVersionsResponse) StatusCode() int { return 0 } +type PostFleetAgentsBulkMigrateResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + ActionId string `json:"actionId"` + } + JSON400 *struct { + Attributes interface{} `json:"attributes"` + Error *string `json:"error,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + Message string `json:"message"` + StatusCode *float32 `json:"statusCode,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r PostFleetAgentsBulkMigrateResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostFleetAgentsBulkMigrateResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type PostFleetAgentsBulkReassignResponse struct { Body []byte HTTPResponse *http.Response @@ -117034,6 +117256,37 @@ func (r PostFleetAgentsAgentidActionsResponse) StatusCode() int { return 0 } +type PostFleetAgentsAgentidMigrateResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + ActionId string `json:"actionId"` + } + JSON400 *struct { + Attributes interface{} `json:"attributes"` + Error *string `json:"error,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + Message string `json:"message"` + StatusCode *float32 `json:"statusCode,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r PostFleetAgentsAgentidMigrateResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r PostFleetAgentsAgentidMigrateResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type PostFleetAgentsAgentidReassignResponse struct { Body []byte HTTPResponse *http.Response @@ -125550,6 +125803,56 @@ func (r UpdateDataViewDefaultResponse) StatusCode() int { return 0 } +type GetDefaultDataViewDefaultResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + DataViewId *string `json:"data_view_id,omitempty"` + } + JSON400 *DataViews400Response +} + +// Status returns HTTPResponse.Status +func (r GetDefaultDataViewDefaultResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetDefaultDataViewDefaultResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type SetDefaultDatailViewDefaultResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Acknowledged *bool `json:"acknowledged,omitempty"` + } + JSON400 *DataViews400Response +} + +// Status returns HTTPResponse.Status +func (r SetDefaultDatailViewDefaultResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r SetDefaultDatailViewDefaultResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type PostMaintenanceWindowResponse struct { Body []byte HTTPResponse *http.Response @@ -127327,32 +127630,6 @@ func (c *ClientWithResponses) UpdateRuntimeFieldDefaultWithResponse(ctx context. return ParseUpdateRuntimeFieldDefaultResponse(rsp) } -// GetDefaultDataViewDefaultWithResponse request returning *GetDefaultDataViewDefaultResponse -func (c *ClientWithResponses) GetDefaultDataViewDefaultWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetDefaultDataViewDefaultResponse, error) { - rsp, err := c.GetDefaultDataViewDefault(ctx, reqEditors...) - if err != nil { - return nil, err - } - return ParseGetDefaultDataViewDefaultResponse(rsp) -} - -// SetDefaultDatailViewDefaultWithBodyWithResponse request with arbitrary body returning *SetDefaultDatailViewDefaultResponse -func (c *ClientWithResponses) SetDefaultDatailViewDefaultWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) { - rsp, err := c.SetDefaultDatailViewDefaultWithBody(ctx, contentType, body, reqEditors...) - if err != nil { - return nil, err - } - return ParseSetDefaultDatailViewDefaultResponse(rsp) -} - -func (c *ClientWithResponses) SetDefaultDatailViewDefaultWithResponse(ctx context.Context, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) { - rsp, err := c.SetDefaultDatailViewDefault(ctx, body, reqEditors...) - if err != nil { - return nil, err - } - return ParseSetDefaultDatailViewDefaultResponse(rsp) -} - // SwapDataViewsDefaultWithBodyWithResponse request with arbitrary body returning *SwapDataViewsDefaultResponse func (c *ClientWithResponses) SwapDataViewsDefaultWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SwapDataViewsDefaultResponse, error) { rsp, err := c.SwapDataViewsDefaultWithBody(ctx, contentType, body, reqEditors...) @@ -128826,6 +129103,23 @@ func (c *ClientWithResponses) GetFleetAgentsAvailableVersionsWithResponse(ctx co return ParseGetFleetAgentsAvailableVersionsResponse(rsp) } +// PostFleetAgentsBulkMigrateWithBodyWithResponse request with arbitrary body returning *PostFleetAgentsBulkMigrateResponse +func (c *ClientWithResponses) PostFleetAgentsBulkMigrateWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsBulkMigrateResponse, error) { + rsp, err := c.PostFleetAgentsBulkMigrateWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostFleetAgentsBulkMigrateResponse(rsp) +} + +func (c *ClientWithResponses) PostFleetAgentsBulkMigrateWithResponse(ctx context.Context, body PostFleetAgentsBulkMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*PostFleetAgentsBulkMigrateResponse, error) { + rsp, err := c.PostFleetAgentsBulkMigrate(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostFleetAgentsBulkMigrateResponse(rsp) +} + // PostFleetAgentsBulkReassignWithBodyWithResponse request with arbitrary body returning *PostFleetAgentsBulkReassignResponse func (c *ClientWithResponses) PostFleetAgentsBulkReassignWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsBulkReassignResponse, error) { rsp, err := c.PostFleetAgentsBulkReassignWithBody(ctx, contentType, body, reqEditors...) @@ -129008,6 +129302,23 @@ func (c *ClientWithResponses) PostFleetAgentsAgentidActionsWithResponse(ctx cont return ParsePostFleetAgentsAgentidActionsResponse(rsp) } +// PostFleetAgentsAgentidMigrateWithBodyWithResponse request with arbitrary body returning *PostFleetAgentsAgentidMigrateResponse +func (c *ClientWithResponses) PostFleetAgentsAgentidMigrateWithBodyWithResponse(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidMigrateResponse, error) { + rsp, err := c.PostFleetAgentsAgentidMigrateWithBody(ctx, agentId, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostFleetAgentsAgentidMigrateResponse(rsp) +} + +func (c *ClientWithResponses) PostFleetAgentsAgentidMigrateWithResponse(ctx context.Context, agentId string, body PostFleetAgentsAgentidMigrateJSONRequestBody, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidMigrateResponse, error) { + rsp, err := c.PostFleetAgentsAgentidMigrate(ctx, agentId, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostFleetAgentsAgentidMigrateResponse(rsp) +} + // PostFleetAgentsAgentidReassignWithBodyWithResponse request with arbitrary body returning *PostFleetAgentsAgentidReassignResponse func (c *ClientWithResponses) PostFleetAgentsAgentidReassignWithBodyWithResponse(ctx context.Context, agentId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostFleetAgentsAgentidReassignResponse, error) { rsp, err := c.PostFleetAgentsAgentidReassignWithBody(ctx, agentId, contentType, body, reqEditors...) @@ -132387,6 +132698,32 @@ func (c *ClientWithResponses) UpdateDataViewDefaultWithResponse(ctx context.Cont return ParseUpdateDataViewDefaultResponse(rsp) } +// GetDefaultDataViewDefaultWithResponse request returning *GetDefaultDataViewDefaultResponse +func (c *ClientWithResponses) GetDefaultDataViewDefaultWithResponse(ctx context.Context, spaceId SpaceId, reqEditors ...RequestEditorFn) (*GetDefaultDataViewDefaultResponse, error) { + rsp, err := c.GetDefaultDataViewDefault(ctx, spaceId, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetDefaultDataViewDefaultResponse(rsp) +} + +// SetDefaultDatailViewDefaultWithBodyWithResponse request with arbitrary body returning *SetDefaultDatailViewDefaultResponse +func (c *ClientWithResponses) SetDefaultDatailViewDefaultWithBodyWithResponse(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) { + rsp, err := c.SetDefaultDatailViewDefaultWithBody(ctx, spaceId, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDefaultDatailViewDefaultResponse(rsp) +} + +func (c *ClientWithResponses) SetDefaultDatailViewDefaultWithResponse(ctx context.Context, spaceId SpaceId, body SetDefaultDatailViewDefaultJSONRequestBody, reqEditors ...RequestEditorFn) (*SetDefaultDatailViewDefaultResponse, error) { + rsp, err := c.SetDefaultDatailViewDefault(ctx, spaceId, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseSetDefaultDatailViewDefaultResponse(rsp) +} + // PostMaintenanceWindowWithBodyWithResponse request with arbitrary body returning *PostMaintenanceWindowResponse func (c *ClientWithResponses) PostMaintenanceWindowWithBodyWithResponse(ctx context.Context, spaceId SpaceId, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostMaintenanceWindowResponse, error) { rsp, err := c.PostMaintenanceWindowWithBody(ctx, spaceId, contentType, body, reqEditors...) @@ -137309,76 +137646,6 @@ func ParseUpdateRuntimeFieldDefaultResponse(rsp *http.Response) (*UpdateRuntimeF return response, nil } -// ParseGetDefaultDataViewDefaultResponse parses an HTTP response from a GetDefaultDataViewDefaultWithResponse call -func ParseGetDefaultDataViewDefaultResponse(rsp *http.Response) (*GetDefaultDataViewDefaultResponse, error) { - bodyBytes, err := io.ReadAll(rsp.Body) - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &GetDefaultDataViewDefaultResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest struct { - DataViewId *string `json:"data_view_id,omitempty"` - } - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: - var dest DataViews400Response - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON400 = &dest - - } - - return response, nil -} - -// ParseSetDefaultDatailViewDefaultResponse parses an HTTP response from a SetDefaultDatailViewDefaultWithResponse call -func ParseSetDefaultDatailViewDefaultResponse(rsp *http.Response) (*SetDefaultDatailViewDefaultResponse, error) { - bodyBytes, err := io.ReadAll(rsp.Body) - defer func() { _ = rsp.Body.Close() }() - if err != nil { - return nil, err - } - - response := &SetDefaultDatailViewDefaultResponse{ - Body: bodyBytes, - HTTPResponse: rsp, - } - - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest struct { - Acknowledged *bool `json:"acknowledged,omitempty"` - } - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: - var dest DataViews400Response - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON400 = &dest - - } - - return response, nil -} - // ParseSwapDataViewsDefaultResponse parses an HTTP response from a SwapDataViewsDefaultWithResponse call func ParseSwapDataViewsDefaultResponse(rsp *http.Response) (*SwapDataViewsDefaultResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -138921,7 +139188,19 @@ func ParseEndpointFileInfoResponse(rsp *http.Response) (*EndpointFileInfoRespons switch { case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest SecurityEndpointManagementAPISuccessResponse + var dest struct { + Data *struct { + ActionId *string `json:"actionId,omitempty"` + AgentId *string `json:"agentId,omitempty"` + AgentType *string `json:"agentType,omitempty"` + Created *time.Time `json:"created,omitempty"` + Id *string `json:"id,omitempty"` + MimeType *string `json:"mimeType,omitempty"` + Name *string `json:"name,omitempty"` + Size *float32 `json:"size,omitempty"` + Status *EndpointFileInfo200DataStatus `json:"status,omitempty"` + } `json:"data,omitempty"` + } if err := json.Unmarshal(bodyBytes, &dest); err != nil { return nil, err } @@ -138945,16 +139224,6 @@ func ParseEndpointFileDownloadResponse(rsp *http.Response) (*EndpointFileDownloa HTTPResponse: rsp, } - switch { - case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: - var dest SecurityEndpointManagementAPISuccessResponse - if err := json.Unmarshal(bodyBytes, &dest); err != nil { - return nil, err - } - response.JSON200 = &dest - - } - return response, nil } @@ -142691,6 +142960,47 @@ func ParseGetFleetAgentsAvailableVersionsResponse(rsp *http.Response) (*GetFleet return response, nil } +// ParsePostFleetAgentsBulkMigrateResponse parses an HTTP response from a PostFleetAgentsBulkMigrateWithResponse call +func ParsePostFleetAgentsBulkMigrateResponse(rsp *http.Response) (*PostFleetAgentsBulkMigrateResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostFleetAgentsBulkMigrateResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + ActionId string `json:"actionId"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + Attributes interface{} `json:"attributes"` + Error *string `json:"error,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + Message string `json:"message"` + StatusCode *float32 `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + // ParsePostFleetAgentsBulkReassignResponse parses an HTTP response from a PostFleetAgentsBulkReassignWithResponse call func ParsePostFleetAgentsBulkReassignResponse(rsp *http.Response) (*PostFleetAgentsBulkReassignResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -143434,6 +143744,47 @@ func ParsePostFleetAgentsAgentidActionsResponse(rsp *http.Response) (*PostFleetA return response, nil } +// ParsePostFleetAgentsAgentidMigrateResponse parses an HTTP response from a PostFleetAgentsAgentidMigrateWithResponse call +func ParsePostFleetAgentsAgentidMigrateResponse(rsp *http.Response) (*PostFleetAgentsAgentidMigrateResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &PostFleetAgentsAgentidMigrateResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + ActionId string `json:"actionId"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest struct { + Attributes interface{} `json:"attributes"` + Error *string `json:"error,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + Message string `json:"message"` + StatusCode *float32 `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + // ParsePostFleetAgentsAgentidReassignResponse parses an HTTP response from a PostFleetAgentsAgentidReassignWithResponse call func ParsePostFleetAgentsAgentidReassignResponse(rsp *http.Response) (*PostFleetAgentsAgentidReassignResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -152909,6 +153260,76 @@ func ParseUpdateDataViewDefaultResponse(rsp *http.Response) (*UpdateDataViewDefa return response, nil } +// ParseGetDefaultDataViewDefaultResponse parses an HTTP response from a GetDefaultDataViewDefaultWithResponse call +func ParseGetDefaultDataViewDefaultResponse(rsp *http.Response) (*GetDefaultDataViewDefaultResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetDefaultDataViewDefaultResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + DataViewId *string `json:"data_view_id,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest DataViews400Response + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + +// ParseSetDefaultDatailViewDefaultResponse parses an HTTP response from a SetDefaultDatailViewDefaultWithResponse call +func ParseSetDefaultDatailViewDefaultResponse(rsp *http.Response) (*SetDefaultDatailViewDefaultResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &SetDefaultDatailViewDefaultResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Acknowledged *bool `json:"acknowledged,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest DataViews400Response + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + } + + return response, nil +} + // ParsePostMaintenanceWindowResponse parses an HTTP response from a PostMaintenanceWindowWithResponse call func ParsePostMaintenanceWindowResponse(rsp *http.Response) (*PostMaintenanceWindowResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/generated/kbapi/transform_schema.go b/generated/kbapi/transform_schema.go index 962151838..1e6a3e237 100644 --- a/generated/kbapi/transform_schema.go +++ b/generated/kbapi/transform_schema.go @@ -690,6 +690,7 @@ func transformKibanaPaths(schema *Schema) { "/api/maintenance_window/{id}", "/api/actions/connector/{id}", "/api/actions/connectors", + "/api/data_views/default", } // Add a spaceId parameter if not already present diff --git a/internal/clients/kibana_oapi/data_views.go b/internal/clients/kibana_oapi/data_views.go index e20e1bbd1..004c13e6e 100644 --- a/internal/clients/kibana_oapi/data_views.go +++ b/internal/clients/kibana_oapi/data_views.go @@ -89,8 +89,8 @@ func DeleteDataView(ctx context.Context, client *Client, spaceID string, viewID } // GetDefaultDataView reads the default data view from the API. -func GetDefaultDataView(ctx context.Context, client *Client) (*string, diag.Diagnostics) { - resp, err := client.API.GetDefaultDataViewDefaultWithResponse(ctx) +func GetDefaultDataView(ctx context.Context, client *Client, spaceID string) (*string, diag.Diagnostics) { + resp, err := client.API.GetDefaultDataViewDefaultWithResponse(ctx, spaceID) if err != nil { return nil, diagutil.FrameworkDiagFromError(err) } @@ -107,8 +107,8 @@ func GetDefaultDataView(ctx context.Context, client *Client) (*string, diag.Diag } // SetDefaultDataView sets the default data view. -func SetDefaultDataView(ctx context.Context, client *Client, req kbapi.SetDefaultDatailViewDefaultJSONRequestBody) diag.Diagnostics { - resp, err := client.API.SetDefaultDatailViewDefaultWithResponse(ctx, req) +func SetDefaultDataView(ctx context.Context, client *Client, spaceID string, req kbapi.SetDefaultDatailViewDefaultJSONRequestBody) diag.Diagnostics { + resp, err := client.API.SetDefaultDatailViewDefaultWithResponse(ctx, spaceID, req) if err != nil { return diagutil.FrameworkDiagFromError(err) } diff --git a/internal/kibana/default_data_view/acc_test.go b/internal/kibana/default_data_view/acc_test.go index 6efffeb4d..742db176b 100644 --- a/internal/kibana/default_data_view/acc_test.go +++ b/internal/kibana/default_data_view/acc_test.go @@ -25,18 +25,20 @@ func TestAccResourceDefaultDataView(t *testing.T) { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), Config: testAccResourceDefaultDataViewBasic(indexName1), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "force", "true"), resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "skip_delete", "false"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "space_id", "default"), ), }, { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), Config: testAccResourceDefaultDataViewUpdate(indexName1, indexName2), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "space_id", "default"), ), }, }, @@ -54,8 +56,32 @@ func TestAccResourceDefaultDataViewWithSkipDelete(t *testing.T) { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), Config: testAccResourceDefaultDataViewWithSkipDelete(indexName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "skip_delete", "true"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "space_id", "default"), + ), + }, + }, + }) +} + +func TestAccResourceDefaultDataViewWithCustomSpace(t *testing.T) { + indexName := "my-index-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) + spaceID := "test-space-" + sdkacctest.RandStringFromCharSet(6, sdkacctest.CharSetAlphaNum) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ProtoV6ProviderFactories: acctest.Providers, + Steps: []resource.TestStep{ + { + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), + Config: testAccResourceDefaultDataViewWithCustomSpace(indexName, spaceID), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", spaceID), + resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "force", "true"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "skip_delete", "false"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "space_id", spaceID), ), }, }, @@ -152,3 +178,37 @@ resource "elasticstack_kibana_default_data_view" "test" { } `, indexName, indexName) } + +func testAccResourceDefaultDataViewWithCustomSpace(indexName, spaceID string) string { + return fmt.Sprintf(` +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_kibana_space" "test_space" { + space_id = "%s" + name = "Test Space %s" + description = "Test space for default data view" +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = "%s" + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + space_id = elasticstack_kibana_space.test_space.space_id + data_view = { + title = "%s*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + space_id = elasticstack_kibana_space.test_space.space_id + data_view_id = elasticstack_kibana_data_view.dv.data_view.id + force = true +} +`, spaceID, spaceID, indexName, indexName) +} diff --git a/internal/kibana/default_data_view/create.go b/internal/kibana/default_data_view/create.go index 20c946f86..8df8abdb9 100644 --- a/internal/kibana/default_data_view/create.go +++ b/internal/kibana/default_data_view/create.go @@ -5,41 +5,47 @@ import ( "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" ) func (r *DefaultDataViewResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { - var plan defaultDataViewModel - diags := req.Plan.Get(ctx, &plan) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return + resp.Diagnostics.Append(r.setDefaultDataView(ctx, req.Plan, &resp.State)...) +} + +// setDefaultDataView is a helper method that contains the core logic for setting the default data view. +func (r *DefaultDataViewResource) setDefaultDataView(ctx context.Context, plan tfsdk.Plan, state *tfsdk.State) diag.Diagnostics { + var model defaultDataViewModel + diags := plan.Get(ctx, &model) + if diags.HasError() { + return diags } client, err := r.client.GetKibanaOapiClient() if err != nil { - resp.Diagnostics.AddError("unable to get kibana client", err.Error()) - return + diags.AddError("unable to get kibana client", err.Error()) + return diags } - dataViewID := plan.DataViewID.ValueString() - force := plan.Force.ValueBool() - + dataViewID := model.DataViewID.ValueString() + force := model.Force.ValueBool() + spaceID := model.SpaceID.ValueString() setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ DataViewId: &dataViewID, Force: &force, } - diags = kibana_oapi.SetDefaultDataView(ctx, client, setReq) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return + apiDiags := kibana_oapi.SetDefaultDataView(ctx, client, spaceID, setReq) + diags.Append(apiDiags...) + if diags.HasError() { + return diags } - // Set a static ID since there's only one default data view setting - plan.ID = types.StringValue("default") + // Use the space_id as the resource ID + model.ID = types.StringValue(spaceID) - diags = resp.State.Set(ctx, plan) - resp.Diagnostics.Append(diags...) + diags = state.Set(ctx, model) + return diags } diff --git a/internal/kibana/default_data_view/delete.go b/internal/kibana/default_data_view/delete.go index 7b3fdcbd2..1a7bd6bc6 100644 --- a/internal/kibana/default_data_view/delete.go +++ b/internal/kibana/default_data_view/delete.go @@ -5,6 +5,7 @@ import ( "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" + "github.com/elastic/terraform-provider-elasticstack/internal/utils" "github.com/hashicorp/terraform-plugin-framework/resource" ) @@ -27,15 +28,16 @@ func (r *DefaultDataViewResource) Delete(ctx context.Context, req resource.Delet return } - // Unset the default data view by setting it to null - var nullDataViewID *string = nil - force := true + spaceID := state.SpaceID.ValueString() + if spaceID == "" { + spaceID = "default" + } + // Unset the default data view by setting it to null setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ - DataViewId: nullDataViewID, - Force: &force, + Force: utils.Pointer(true), } - diags = kibana_oapi.SetDefaultDataView(ctx, client, setReq) + diags = kibana_oapi.SetDefaultDataView(ctx, client, spaceID, setReq) resp.Diagnostics.Append(diags...) } diff --git a/internal/kibana/default_data_view/models.go b/internal/kibana/default_data_view/models.go index b42103ce2..f1dc34c65 100644 --- a/internal/kibana/default_data_view/models.go +++ b/internal/kibana/default_data_view/models.go @@ -9,4 +9,5 @@ type defaultDataViewModel struct { DataViewID types.String `tfsdk:"data_view_id"` Force types.Bool `tfsdk:"force"` SkipDelete types.Bool `tfsdk:"skip_delete"` + SpaceID types.String `tfsdk:"space_id"` } diff --git a/internal/kibana/default_data_view/read.go b/internal/kibana/default_data_view/read.go index 6e4e3d579..19d041c7b 100644 --- a/internal/kibana/default_data_view/read.go +++ b/internal/kibana/default_data_view/read.go @@ -22,7 +22,12 @@ func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadReq return } - defaultDataViewID, diags := kibana_oapi.GetDefaultDataView(ctx, client) + spaceID := state.SpaceID.ValueString() + if spaceID == "" { + spaceID = "default" + } + + defaultDataViewID, diags := kibana_oapi.GetDefaultDataView(ctx, client, spaceID) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return @@ -36,9 +41,9 @@ func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadReq // Update state with current default data view state.DataViewID = types.StringValue(*defaultDataViewID) - // Keep the ID as "default" - it should remain static + // Use the space_id as the resource ID if state.ID.IsNull() || state.ID.IsUnknown() { - state.ID = types.StringValue("default") + state.ID = types.StringValue(spaceID) } diags = resp.State.Set(ctx, state) diff --git a/internal/kibana/default_data_view/schema.go b/internal/kibana/default_data_view/schema.go index 945c88879..99b793cee 100644 --- a/internal/kibana/default_data_view/schema.go +++ b/internal/kibana/default_data_view/schema.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/schema/validator" ) @@ -37,8 +38,6 @@ func getSchema() schema.Schema { "force": schema.BoolAttribute{ MarkdownDescription: "Update an existing default data view identifier. If set to false and a default data view already exists, the operation will fail.", Optional: true, - Computed: true, - Default: booldefault.StaticBool(true), }, "skip_delete": schema.BoolAttribute{ MarkdownDescription: "If set to true, the default data view will not be unset when the resource is destroyed. The existing default data view will remain unchanged.", @@ -46,6 +45,15 @@ func getSchema() schema.Schema { Computed: true, Default: booldefault.StaticBool(false), }, + "space_id": schema.StringAttribute{ + MarkdownDescription: "The Kibana space ID to set the default data view in. Defaults to `default`.", + Optional: true, + Computed: true, + Default: stringdefault.StaticString("default"), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), + }, + }, }, } } diff --git a/internal/kibana/default_data_view/update.go b/internal/kibana/default_data_view/update.go index 2472b6837..49d327384 100644 --- a/internal/kibana/default_data_view/update.go +++ b/internal/kibana/default_data_view/update.go @@ -3,43 +3,9 @@ package default_data_view import ( "context" - "github.com/elastic/terraform-provider-elasticstack/generated/kbapi" - "github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/types" ) func (r *DefaultDataViewResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { - var plan defaultDataViewModel - diags := req.Plan.Get(ctx, &plan) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - client, err := r.client.GetKibanaOapiClient() - if err != nil { - resp.Diagnostics.AddError("unable to get kibana client", err.Error()) - return - } - - dataViewID := plan.DataViewID.ValueString() - force := plan.Force.ValueBool() - - setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ - DataViewId: &dataViewID, - Force: &force, - } - - diags = kibana_oapi.SetDefaultDataView(ctx, client, setReq) - resp.Diagnostics.Append(diags...) - if resp.Diagnostics.HasError() { - return - } - - // Keep the ID as "default" - it should remain static - plan.ID = types.StringValue("default") - - diags = resp.State.Set(ctx, plan) - resp.Diagnostics.Append(diags...) + resp.Diagnostics.Append(r.setDefaultDataView(ctx, req.Plan, &resp.State)...) } From 8e5e1d9f2a66d9d5efa8c0191475cfba4b3560af Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Mon, 20 Oct 2025 19:29:03 +1100 Subject: [PATCH 6/6] Support removing the default data view --- docs/resources/kibana_default_data_view.md | 5 +- internal/clients/kibana_oapi/data_views.go | 2 +- internal/kibana/default_data_view/acc_test.go | 175 +++++------------- internal/kibana/default_data_view/create.go | 4 +- internal/kibana/default_data_view/delete.go | 3 - internal/kibana/default_data_view/read.go | 17 +- internal/kibana/default_data_view/schema.go | 4 +- .../default_data_view/test_data/basic.tf | 26 +++ .../test_data/custom_space.tf | 39 ++++ .../test_data/skip_delete.tf | 27 +++ .../default_data_view/test_data/unset.tf | 42 +++++ .../default_data_view/test_data/update.tf | 43 +++++ 12 files changed, 231 insertions(+), 156 deletions(-) create mode 100644 internal/kibana/default_data_view/test_data/basic.tf create mode 100644 internal/kibana/default_data_view/test_data/custom_space.tf create mode 100644 internal/kibana/default_data_view/test_data/skip_delete.tf create mode 100644 internal/kibana/default_data_view/test_data/unset.tf create mode 100644 internal/kibana/default_data_view/test_data/update.tf diff --git a/docs/resources/kibana_default_data_view.md b/docs/resources/kibana_default_data_view.md index 9c8cf8429..92bc132a4 100644 --- a/docs/resources/kibana_default_data_view.md +++ b/docs/resources/kibana_default_data_view.md @@ -37,12 +37,9 @@ resource "elasticstack_kibana_default_data_view" "default" { ## Schema -### Required - -- `data_view_id` (String) The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Use `null` to unset the default data view. - ### Optional +- `data_view_id` (String) The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Leave this unset (or explicitly `null`) to unset the default data view. - `force` (Boolean) Update an existing default data view identifier. If set to false and a default data view already exists, the operation will fail. - `skip_delete` (Boolean) If set to true, the default data view will not be unset when the resource is destroyed. The existing default data view will remain unchanged. - `space_id` (String) The Kibana space ID to set the default data view in. Defaults to `default`. diff --git a/internal/clients/kibana_oapi/data_views.go b/internal/clients/kibana_oapi/data_views.go index 004c13e6e..00aca6f13 100644 --- a/internal/clients/kibana_oapi/data_views.go +++ b/internal/clients/kibana_oapi/data_views.go @@ -97,7 +97,7 @@ func GetDefaultDataView(ctx context.Context, client *Client, spaceID string) (*s switch resp.StatusCode() { case http.StatusOK: - if resp.JSON200 != nil && resp.JSON200.DataViewId != nil { + if resp.JSON200 != nil && resp.JSON200.DataViewId != nil && *resp.JSON200.DataViewId != "" { return resp.JSON200.DataViewId, nil } return nil, nil diff --git a/internal/kibana/default_data_view/acc_test.go b/internal/kibana/default_data_view/acc_test.go index 742db176b..1ccb316b6 100644 --- a/internal/kibana/default_data_view/acc_test.go +++ b/internal/kibana/default_data_view/acc_test.go @@ -1,18 +1,31 @@ package default_data_view_test import ( - "fmt" + "embed" "testing" "github.com/elastic/terraform-provider-elasticstack/internal/acctest" "github.com/elastic/terraform-provider-elasticstack/internal/versionutils" "github.com/hashicorp/go-version" + "github.com/hashicorp/terraform-plugin-testing/config" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" ) +//go:embed test_data/*.tf +var testDataFS embed.FS + var minDataViewAPISupport = version.Must(version.NewVersion("8.1.0")) +// loadTestData reads and returns the content of a test data file +func loadTestData(filename string) string { + data, err := testDataFS.ReadFile("test_data/" + filename) + if err != nil { + panic("Failed to load test data file: " + filename + " - " + err.Error()) + } + return string(data) +} + func TestAccResourceDefaultDataView(t *testing.T) { indexName1 := "my-index-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) indexName2 := "my-other-index-" + sdkacctest.RandStringFromCharSet(4, sdkacctest.CharSetAlphaNum) @@ -23,7 +36,10 @@ func TestAccResourceDefaultDataView(t *testing.T) { Steps: []resource.TestStep{ { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), - Config: testAccResourceDefaultDataViewBasic(indexName1), + Config: loadTestData("basic.tf"), + ConfigVariables: config.Variables{ + "index_name": config.StringVariable(indexName1), + }, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), @@ -34,13 +50,30 @@ func TestAccResourceDefaultDataView(t *testing.T) { }, { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), - Config: testAccResourceDefaultDataViewUpdate(indexName1, indexName2), + Config: loadTestData("update.tf"), + ConfigVariables: config.Variables{ + "index_name1": config.StringVariable(indexName1), + "index_name2": config.StringVariable(indexName2), + }, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "space_id", "default"), ), }, + { + SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), + Config: loadTestData("unset.tf"), + ConfigVariables: config.Variables{ + "index_name1": config.StringVariable(indexName1), + "index_name2": config.StringVariable(indexName2), + }, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), + resource.TestCheckNoResourceAttr("elasticstack_kibana_default_data_view.test", "data_view_id"), + resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "space_id", "default"), + ), + }, }, }) } @@ -54,7 +87,10 @@ func TestAccResourceDefaultDataViewWithSkipDelete(t *testing.T) { Steps: []resource.TestStep{ { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), - Config: testAccResourceDefaultDataViewWithSkipDelete(indexName), + Config: loadTestData("skip_delete.tf"), + ConfigVariables: config.Variables{ + "index_name": config.StringVariable(indexName), + }, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", "default"), resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "skip_delete", "true"), @@ -75,7 +111,11 @@ func TestAccResourceDefaultDataViewWithCustomSpace(t *testing.T) { Steps: []resource.TestStep{ { SkipFunc: versionutils.CheckIfVersionIsUnsupported(minDataViewAPISupport), - Config: testAccResourceDefaultDataViewWithCustomSpace(indexName, spaceID), + Config: loadTestData("custom_space.tf"), + ConfigVariables: config.Variables{ + "index_name": config.StringVariable(indexName), + "space_id": config.StringVariable(spaceID), + }, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("elasticstack_kibana_default_data_view.test", "id", spaceID), resource.TestCheckResourceAttrSet("elasticstack_kibana_default_data_view.test", "data_view_id"), @@ -87,128 +127,3 @@ func TestAccResourceDefaultDataViewWithCustomSpace(t *testing.T) { }, }) } - -func testAccResourceDefaultDataViewBasic(indexName string) string { - return fmt.Sprintf(` -provider "elasticstack" { - elasticsearch {} - kibana {} -} - -resource "elasticstack_elasticsearch_index" "my_index" { - name = "%s" - deletion_protection = false -} - -resource "elasticstack_kibana_data_view" "dv" { - data_view = { - title = "%s*" - } - depends_on = [elasticstack_elasticsearch_index.my_index] -} - -resource "elasticstack_kibana_default_data_view" "test" { - data_view_id = elasticstack_kibana_data_view.dv.data_view.id - force = true -} -`, indexName, indexName) -} - -func testAccResourceDefaultDataViewUpdate(indexName1, indexName2 string) string { - return fmt.Sprintf(` -provider "elasticstack" { - elasticsearch {} - kibana {} -} - -resource "elasticstack_elasticsearch_index" "my_index" { - name = "%s" - deletion_protection = false -} - -resource "elasticstack_elasticsearch_index" "my_other_index" { - name = "%s" - deletion_protection = false -} - -resource "elasticstack_kibana_data_view" "dv" { - data_view = { - title = "%s*" - } - depends_on = [elasticstack_elasticsearch_index.my_index] -} - -resource "elasticstack_kibana_data_view" "dv2" { - data_view = { - title = "%s*" - } - depends_on = [elasticstack_elasticsearch_index.my_other_index] -} - -resource "elasticstack_kibana_default_data_view" "test" { - data_view_id = elasticstack_kibana_data_view.dv2.data_view.id - force = true -} -`, indexName1, indexName2, indexName1, indexName2) -} - -func testAccResourceDefaultDataViewWithSkipDelete(indexName string) string { - return fmt.Sprintf(` -provider "elasticstack" { - elasticsearch {} - kibana {} -} - -resource "elasticstack_elasticsearch_index" "my_index" { - name = "%s" - deletion_protection = false -} - -resource "elasticstack_kibana_data_view" "dv" { - data_view = { - title = "%s*" - } - depends_on = [elasticstack_elasticsearch_index.my_index] -} - -resource "elasticstack_kibana_default_data_view" "test" { - data_view_id = elasticstack_kibana_data_view.dv.data_view.id - force = true - skip_delete = true -} -`, indexName, indexName) -} - -func testAccResourceDefaultDataViewWithCustomSpace(indexName, spaceID string) string { - return fmt.Sprintf(` -provider "elasticstack" { - elasticsearch {} - kibana {} -} - -resource "elasticstack_kibana_space" "test_space" { - space_id = "%s" - name = "Test Space %s" - description = "Test space for default data view" -} - -resource "elasticstack_elasticsearch_index" "my_index" { - name = "%s" - deletion_protection = false -} - -resource "elasticstack_kibana_data_view" "dv" { - space_id = elasticstack_kibana_space.test_space.space_id - data_view = { - title = "%s*" - } - depends_on = [elasticstack_elasticsearch_index.my_index] -} - -resource "elasticstack_kibana_default_data_view" "test" { - space_id = elasticstack_kibana_space.test_space.space_id - data_view_id = elasticstack_kibana_data_view.dv.data_view.id - force = true -} -`, spaceID, spaceID, indexName, indexName) -} diff --git a/internal/kibana/default_data_view/create.go b/internal/kibana/default_data_view/create.go index 8df8abdb9..2f04767a3 100644 --- a/internal/kibana/default_data_view/create.go +++ b/internal/kibana/default_data_view/create.go @@ -29,11 +29,11 @@ func (r *DefaultDataViewResource) setDefaultDataView(ctx context.Context, plan t return diags } - dataViewID := model.DataViewID.ValueString() + dataViewID := model.DataViewID.ValueStringPointer() force := model.Force.ValueBool() spaceID := model.SpaceID.ValueString() setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ - DataViewId: &dataViewID, + DataViewId: dataViewID, Force: &force, } diff --git a/internal/kibana/default_data_view/delete.go b/internal/kibana/default_data_view/delete.go index 1a7bd6bc6..bc32c0ebd 100644 --- a/internal/kibana/default_data_view/delete.go +++ b/internal/kibana/default_data_view/delete.go @@ -29,9 +29,6 @@ func (r *DefaultDataViewResource) Delete(ctx context.Context, req resource.Delet } spaceID := state.SpaceID.ValueString() - if spaceID == "" { - spaceID = "default" - } // Unset the default data view by setting it to null setReq := kbapi.SetDefaultDatailViewDefaultJSONRequestBody{ diff --git a/internal/kibana/default_data_view/read.go b/internal/kibana/default_data_view/read.go index 19d041c7b..2ebbdd2cf 100644 --- a/internal/kibana/default_data_view/read.go +++ b/internal/kibana/default_data_view/read.go @@ -23,28 +23,17 @@ func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadReq } spaceID := state.SpaceID.ValueString() - if spaceID == "" { - spaceID = "default" - } - defaultDataViewID, diags := kibana_oapi.GetDefaultDataView(ctx, client, spaceID) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { return } - // If no default data view is set, remove from state - if defaultDataViewID == nil || *defaultDataViewID == "" { - resp.State.RemoveResource(ctx) - return - } - // Update state with current default data view - state.DataViewID = types.StringValue(*defaultDataViewID) + state.DataViewID = types.StringPointerValue(defaultDataViewID) + // Use the space_id as the resource ID - if state.ID.IsNull() || state.ID.IsUnknown() { - state.ID = types.StringValue(spaceID) - } + state.ID = types.StringValue(spaceID) diags = resp.State.Set(ctx, state) resp.Diagnostics.Append(diags...) diff --git a/internal/kibana/default_data_view/schema.go b/internal/kibana/default_data_view/schema.go index 99b793cee..c7603f80c 100644 --- a/internal/kibana/default_data_view/schema.go +++ b/internal/kibana/default_data_view/schema.go @@ -29,8 +29,8 @@ func getSchema() schema.Schema { }, }, "data_view_id": schema.StringAttribute{ - MarkdownDescription: "The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Use `null` to unset the default data view.", - Required: true, + MarkdownDescription: "The data view identifier to set as default. NOTE: The API does not validate whether it is a valid identifier. Leave this unset (or explicitly `null`) to unset the default data view.", + Optional: true, Validators: []validator.String{ stringvalidator.LengthAtLeast(1), }, diff --git a/internal/kibana/default_data_view/test_data/basic.tf b/internal/kibana/default_data_view/test_data/basic.tf new file mode 100644 index 000000000..1f3ab00dc --- /dev/null +++ b/internal/kibana/default_data_view/test_data/basic.tf @@ -0,0 +1,26 @@ +variable "index_name" { + description = "The name of the Elasticsearch index" + type = string +} + +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = var.index_name + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "${var.index_name}*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + data_view_id = elasticstack_kibana_data_view.dv.data_view.id + force = true +} \ No newline at end of file diff --git a/internal/kibana/default_data_view/test_data/custom_space.tf b/internal/kibana/default_data_view/test_data/custom_space.tf new file mode 100644 index 000000000..10878d9e3 --- /dev/null +++ b/internal/kibana/default_data_view/test_data/custom_space.tf @@ -0,0 +1,39 @@ +variable "index_name" { + description = "The name of the Elasticsearch index" + type = string +} + +variable "space_id" { + description = "The ID of the Kibana space" + type = string +} + +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_kibana_space" "test_space" { + space_id = var.space_id + name = "Test Space ${var.space_id}" + description = "Test space for default data view" +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = var.index_name + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + space_id = elasticstack_kibana_space.test_space.space_id + data_view = { + title = "${var.index_name}*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + space_id = elasticstack_kibana_space.test_space.space_id + data_view_id = elasticstack_kibana_data_view.dv.data_view.id + force = true +} \ No newline at end of file diff --git a/internal/kibana/default_data_view/test_data/skip_delete.tf b/internal/kibana/default_data_view/test_data/skip_delete.tf new file mode 100644 index 000000000..9f7fba451 --- /dev/null +++ b/internal/kibana/default_data_view/test_data/skip_delete.tf @@ -0,0 +1,27 @@ +variable "index_name" { + description = "The name of the Elasticsearch index" + type = string +} + +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = var.index_name + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "${var.index_name}*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + data_view_id = elasticstack_kibana_data_view.dv.data_view.id + force = true + skip_delete = true +} \ No newline at end of file diff --git a/internal/kibana/default_data_view/test_data/unset.tf b/internal/kibana/default_data_view/test_data/unset.tf new file mode 100644 index 000000000..3f469ded0 --- /dev/null +++ b/internal/kibana/default_data_view/test_data/unset.tf @@ -0,0 +1,42 @@ +variable "index_name1" { + description = "The name of the first Elasticsearch index" + type = string +} + +variable "index_name2" { + description = "The name of the second Elasticsearch index" + type = string +} + +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = var.index_name1 + deletion_protection = false +} + +resource "elasticstack_elasticsearch_index" "my_other_index" { + name = var.index_name2 + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "${var.index_name1}*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_data_view" "dv2" { + data_view = { + title = "${var.index_name2}*" + } + depends_on = [elasticstack_elasticsearch_index.my_other_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + force = true +} \ No newline at end of file diff --git a/internal/kibana/default_data_view/test_data/update.tf b/internal/kibana/default_data_view/test_data/update.tf new file mode 100644 index 000000000..53cd380a4 --- /dev/null +++ b/internal/kibana/default_data_view/test_data/update.tf @@ -0,0 +1,43 @@ +variable "index_name1" { + description = "The name of the first Elasticsearch index" + type = string +} + +variable "index_name2" { + description = "The name of the second Elasticsearch index" + type = string +} + +provider "elasticstack" { + elasticsearch {} + kibana {} +} + +resource "elasticstack_elasticsearch_index" "my_index" { + name = var.index_name1 + deletion_protection = false +} + +resource "elasticstack_elasticsearch_index" "my_other_index" { + name = var.index_name2 + deletion_protection = false +} + +resource "elasticstack_kibana_data_view" "dv" { + data_view = { + title = "${var.index_name1}*" + } + depends_on = [elasticstack_elasticsearch_index.my_index] +} + +resource "elasticstack_kibana_data_view" "dv2" { + data_view = { + title = "${var.index_name2}*" + } + depends_on = [elasticstack_elasticsearch_index.my_other_index] +} + +resource "elasticstack_kibana_default_data_view" "test" { + data_view_id = elasticstack_kibana_data_view.dv2.data_view.id + force = true +} \ No newline at end of file