Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for object type #36

Merged
merged 1 commit into from
Mar 19, 2024
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 docs/resources/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resource "typesense_collection" "test_collection" {
index = true
name = "test_field_2_updated"
optional = true
type = "string"
type = "object"
}

}
10 changes: 10 additions & 0 deletions internal/provider/resource_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{}

Expand All @@ -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)...)
Expand Down Expand Up @@ -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)...)
Expand Down
Loading