Skip to content

Commit 332281f

Browse files
authored
Fixup data views in 8.14 (#663)
* Fixup data view creation in 8.14 Previously Kibana was treating an empty ID as un-set. This change leaves the ID undefined in the json body if it's unknown in the TF plan * Generate docs * Changelog * Also enforce that the title isn't empty
1 parent 0b4e566 commit 332281f

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
## [Unreleased]
22

3+
### Breaking changes
4+
- The `title` attribute is now required in the elasticstack_kibana_data_view resource. In practice the resource didn't work without this set, the schema now enforces it's correctly configured.
5+
36
### Fixed
47

58
- Populate policy_id when importing fleet policies and integrations ([#646](https://github.com/elastic/terraform-provider-elasticstack/pull/646))
69
- Fix alerting rule update crash when backend responds with HTTP 4xx. ([#649](https://github.com/elastic/terraform-provider-elasticstack/pull/649))
10+
- Fix the elasticstack_kibana_data_view resource when not specifying an `id` and running against Kibana 8.14 ([#663](https://github.com/elastic/terraform-provider-elasticstack/pull/663))
711
- Support allow_write_after_shrink when managing ILM policies ([#662](https://github.com/elastic/terraform-provider-elasticstack/pull/662))
812

913
## [0.11.3] - 2024-05-16

docs/resources/kibana_data_view.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ resource "elasticstack_kibana_data_view" "my_data_view" {
4747
<a id="nestedatt--data_view"></a>
4848
### Nested Schema for `data_view`
4949

50+
Required:
51+
52+
- `title` (String) Comma-separated list of data streams, indices, and aliases that you want to search. Supports wildcards (*).
53+
5054
Optional:
5155

5256
- `allow_no_index` (Boolean) Allows the Data view saved object to exist before the data is available.
@@ -58,7 +62,6 @@ Optional:
5862
- `runtime_field_map` (Attributes Map) Map of runtime field definitions by field name. (see [below for nested schema](#nestedatt--data_view--runtime_field_map))
5963
- `source_filters` (List of String) List of field names you want to filter out in Discover.
6064
- `time_field_name` (String) Timestamp field name, which you use for time-based Data views.
61-
- `title` (String) Comma-separated list of data streams, indices, and aliases that you want to search. Supports wildcards (*).
6265

6366
<a id="nestedatt--data_view--field_attrs"></a>
6467
### Nested Schema for `data_view.field_attrs`

internal/kibana/data_view/acc_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,22 @@ func TestAccResourceDataView(t *testing.T) {
6666
}
6767

6868
func testAccResourceDataViewPre8_8DV(indexName string) string {
69-
return `
69+
return fmt.Sprintf(`
7070
provider "elasticstack" {
7171
elasticsearch {}
7272
kibana {}
7373
}
7474
75+
resource "elasticstack_elasticsearch_index" "my_index" {
76+
name = "%s"
77+
deletion_protection = false
78+
}
79+
7580
resource "elasticstack_kibana_data_view" "dv" {
76-
data_view = {}
77-
}`
81+
data_view = {
82+
title = "%s*"
83+
}
84+
}`, indexName, indexName)
7885
}
7986

8087
func testAccResourceDataViewBasicDV(indexName string) string {

internal/kibana/data_view/schema.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/elastic/terraform-provider-elasticstack/generated/data_views"
77
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
8+
"github.com/elastic/terraform-provider-elasticstack/internal/utils"
9+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
810
"github.com/hashicorp/terraform-plugin-framework/diag"
911
"github.com/hashicorp/terraform-plugin-framework/resource"
1012
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
@@ -15,6 +17,7 @@ import (
1517
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
1618
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
1719
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
20+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1821
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1922
"github.com/hashicorp/terraform-plugin-framework/types"
2023
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
@@ -60,10 +63,9 @@ func getSchema() schema.Schema {
6063
Attributes: map[string]schema.Attribute{
6164
"title": schema.StringAttribute{
6265
Description: "Comma-separated list of data streams, indices, and aliases that you want to search. Supports wildcards (*).",
63-
Optional: true,
64-
Computed: true,
65-
PlanModifiers: []planmodifier.String{
66-
stringplanmodifier.UseStateForUnknown(),
66+
Required: true,
67+
Validators: []validator.String{
68+
stringvalidator.LengthAtLeast(1),
6769
},
6870
},
6971
"name": schema.StringAttribute{
@@ -406,16 +408,23 @@ func dataViewFromResponse(resp data_views.DataViewResponseObjectDataView) apiDat
406408

407409
func (m tfDataViewV0) ToCreateRequest(ctx context.Context, spaceID string) (data_views.CreateDataViewRequestObjectDataView, diag.Diagnostics) {
408410
apiModel := data_views.CreateDataViewRequestObjectDataView{
409-
Title: m.Title.ValueString(),
410-
Name: m.Name.ValueStringPointer(),
411-
Id: m.ID.ValueStringPointer(),
412-
TimeFieldName: m.TimeFieldName.ValueStringPointer(),
413-
AllowNoIndex: m.AllowNoIndex.ValueBoolPointer(),
411+
Title: m.Title.ValueString(),
412+
}
413+
414+
if utils.IsKnown(m.ID) {
415+
apiModel.Id = m.ID.ValueStringPointer()
416+
}
417+
418+
if utils.IsKnown(m.Name) {
419+
apiModel.Name = m.Name.ValueStringPointer()
420+
}
421+
422+
if utils.IsKnown(m.TimeFieldName) {
423+
apiModel.TimeFieldName = m.TimeFieldName.ValueStringPointer()
414424
}
415425

416-
// ES versions not supporting name (8.1-8.3) reject requests with this field supplied
417-
if m.Name.IsUnknown() {
418-
apiModel.Name = nil
426+
if utils.IsKnown(m.AllowNoIndex) {
427+
apiModel.AllowNoIndex = m.AllowNoIndex.ValueBoolPointer()
419428
}
420429

421430
var sourceFilters []string

internal/utils/schema.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package utils
22

3-
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/attr"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
)
47

58
func ExpandStringSet(set *schema.Set) []string {
69
var strs []string
@@ -9,3 +12,7 @@ func ExpandStringSet(set *schema.Set) []string {
912
}
1013
return strs
1114
}
15+
16+
func IsKnown(val attr.Value) bool {
17+
return !(val.IsNull() || val.IsUnknown())
18+
}

0 commit comments

Comments
 (0)