Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased]

- Fix a provider crash when interacting with elasticstack_kibana_data_view resources created with 0.11.0. ([#979](https://github.com/elastic/terraform-provider-elasticstack/pull/979))
- Add `max_primary_shard_docs` condition to ILM rollover ([#845](https://github.com/elastic/terraform-provider-elasticstack/pull/845))

## [0.11.13] - 2025-01-09
Expand Down
12 changes: 9 additions & 3 deletions internal/kibana/data_view/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,16 @@ func convertSourceFilter(item string, meta utils.ListMeta) kbapi.DataViewsSource
}

func (model dataViewModel) getViewIDAndSpaceID() (viewID string, spaceID string) {
viewID = model.ID.ValueString()
spaceID = model.SpaceID.ValueString()

resourceID := model.ID.ValueString()
composite, _ := clients.CompositeIdFromStr(resourceID)
viewID = composite.ResourceId
spaceID = composite.ClusterId
maybeCompositeID, _ := clients.CompositeIdFromStr(resourceID)
if maybeCompositeID != nil {
viewID = maybeCompositeID.ResourceId
spaceID = maybeCompositeID.ClusterId
}

return
}

Expand Down
35 changes: 35 additions & 0 deletions internal/kibana/data_view/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,38 @@ func TestToAPIUpdateModel(t *testing.T) {
})
}
}

func Test_dataViewModel_getViewIDAndSpaceID(t *testing.T) {
tests := []struct {
name string
model dataViewModel
expectedViewID string
expectedSpaceID string
}{
{
name: "gets the view and space id from the composite id if set",
model: dataViewModel{
ID: types.StringValue("space-id/view-id"),
},
expectedViewID: "view-id",
expectedSpaceID: "space-id",
},
{
name: "gets the view and space id from the data view if id is not a valid composite id",
model: dataViewModel{
ID: types.StringValue("view-id"),
SpaceID: types.StringValue("space-id"),
},
expectedViewID: "view-id",
expectedSpaceID: "space-id",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viewID, spaceID := tt.model.getViewIDAndSpaceID()
require.Equal(t, tt.expectedViewID, viewID)
require.Equal(t, tt.expectedSpaceID, spaceID)
})
}
}
Loading