Skip to content

Commit cbf0d64

Browse files
Copilottobio
andcommitted
Fix ID consistency and generate documentation
Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
1 parent 46b83f1 commit cbf0d64

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "elasticstack_kibana_default_data_view Resource - terraform-provider-elasticstack"
4+
subcategory: "Kibana"
5+
description: |-
6+
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.
7+
---
8+
9+
# elasticstack_kibana_default_data_view (Resource)
10+
11+
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.
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Required
19+
20+
- `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.
21+
22+
### Optional
23+
24+
- `force` (Boolean) Update an existing default data view identifier. If set to false and a default data view already exists, the operation will fail.
25+
- `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.
26+
27+
### Read-Only
28+
29+
- `id` (String) Internal identifier of the resource.

internal/kibana/default_data_view/create.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package default_data_view
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
87
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
@@ -38,8 +37,8 @@ func (r *DefaultDataViewResource) Create(ctx context.Context, req resource.Creat
3837
return
3938
}
4039

41-
// Set the ID to the data view ID for state tracking
42-
plan.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", dataViewID))
40+
// Set a static ID since there's only one default data view setting
41+
plan.ID = types.StringValue("default")
4342

4443
diags = resp.State.Set(ctx, plan)
4544
resp.Diagnostics.Append(diags...)

internal/kibana/default_data_view/read.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package default_data_view
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
87
"github.com/hashicorp/terraform-plugin-framework/resource"
@@ -37,7 +36,10 @@ func (r *DefaultDataViewResource) Read(ctx context.Context, req resource.ReadReq
3736

3837
// Update state with current default data view
3938
state.DataViewID = types.StringValue(*defaultDataViewID)
40-
state.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", *defaultDataViewID))
39+
// Keep the ID as "default" - it should remain static
40+
if state.ID.IsNull() || state.ID.IsUnknown() {
41+
state.ID = types.StringValue("default")
42+
}
4143

4244
diags = resp.State.Set(ctx, state)
4345
resp.Diagnostics.Append(diags...)

internal/kibana/default_data_view/update.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package default_data_view
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/elastic/terraform-provider-elasticstack/generated/kbapi"
87
"github.com/elastic/terraform-provider-elasticstack/internal/clients/kibana_oapi"
@@ -38,8 +37,8 @@ func (r *DefaultDataViewResource) Update(ctx context.Context, req resource.Updat
3837
return
3938
}
4039

41-
// Update the ID to reflect the new data view ID
42-
plan.ID = types.StringValue(fmt.Sprintf("default-data-view:%s", dataViewID))
40+
// Keep the ID as "default" - it should remain static
41+
plan.ID = types.StringValue("default")
4342

4443
diags = resp.State.Set(ctx, plan)
4544
resp.Diagnostics.Append(diags...)

0 commit comments

Comments
 (0)