From 4f6294a1ab21b61753986a200ce2a131b9273929 Mon Sep 17 00:00:00 2001 From: Alexander Danylenko Date: Tue, 19 Mar 2024 10:33:55 +0200 Subject: [PATCH] feat: Added support for object type --- docs/resources/collection.md | 1 + examples/provider-install-verification/main.tf | 2 +- internal/provider/resource_collection.go | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/resources/collection.md b/docs/resources/collection.md index e985b75..eada9a3 100644 --- a/docs/resources/collection.md +++ b/docs/resources/collection.md @@ -45,6 +45,7 @@ resource "typesense_collection" "my_collection" { ### Optional +- `enable_nested_fields` (Boolean) Enable nested fields, must be enabled to use object/object[] types - `fields` (Block List) (see [below for nested schema](#nestedblock--fields)) ### Read-Only diff --git a/examples/provider-install-verification/main.tf b/examples/provider-install-verification/main.tf index 2989a22..1616849 100644 --- a/examples/provider-install-verification/main.tf +++ b/examples/provider-install-verification/main.tf @@ -34,7 +34,7 @@ resource "typesense_collection" "test_collection" { index = true name = "test_field_2_updated" optional = true - type = "string" + type = "object" } } diff --git a/internal/provider/resource_collection.go b/internal/provider/resource_collection.go index 08a1a20..49a248f 100644 --- a/internal/provider/resource_collection.go +++ b/internal/provider/resource_collection.go @@ -36,6 +36,7 @@ type CollectionResourceModel struct { Name types.String `tfsdk:"name"` DefaultSortingField types.String `tfsdk:"default_sorting_field"` Fields []CollectionResourceFieldModel `tfsdk:"fields"` + EnableNestedFields types.Bool `tfsdk:"enable_nested_fields"` } type CollectionResourceFieldModel struct { @@ -76,6 +77,12 @@ func (r *CollectionResource) Schema(ctx context.Context, req resource.SchemaRequ stringplanmodifier.RequiresReplace(), }, }, + "enable_nested_fields": schema.BoolAttribute{ + Optional: true, + Computed: true, + MarkdownDescription: "Enable nested fields, must be enabled to use object/object[] types", + Default: booldefault.StaticBool(false), + }, }, Blocks: map[string]schema.Block{ "fields": schema.ListNestedBlock{ @@ -163,6 +170,7 @@ func (r *CollectionResource) Create(ctx context.Context, req resource.CreateRequ schema := &api.CollectionSchema{} schema.Name = data.Name.ValueString() schema.DefaultSortingField = data.DefaultSortingField.ValueStringPointer() + schema.EnableNestedFields = data.EnableNestedFields.ValueBoolPointer() fields := []api.Field{} @@ -181,6 +189,7 @@ func (r *CollectionResource) Create(ctx context.Context, req resource.CreateRequ data.Id = types.StringValue(collection.Name) data.Name = types.StringValue(collection.Name) data.DefaultSortingField = types.StringPointerValue(collection.DefaultSortingField) + data.EnableNestedFields = types.BoolPointerValue(collection.EnableNestedFields) data.Fields = flattenCollectionFields(collection.Fields) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) @@ -211,6 +220,7 @@ func (r *CollectionResource) Read(ctx context.Context, req resource.ReadRequest, data.Id = types.StringValue(collection.Name) data.Name = types.StringValue(collection.Name) data.DefaultSortingField = types.StringPointerValue(collection.DefaultSortingField) + data.EnableNestedFields = types.BoolPointerValue(collection.EnableNestedFields) data.Fields = flattenCollectionFields(collection.Fields) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)