Skip to content

Commit

Permalink
Patch state expectations in all_field and image_preprocessing (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
RaynorChavez authored Feb 10, 2025
1 parent 611396d commit c5005e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
with:
go-version-file: 'go.mod'
cache: true
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.*'
- run: go generate ./...
- name: git diff
run: |
Expand Down
32 changes: 22 additions & 10 deletions internal/provider/indices_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,22 @@ func (r *indicesResource) Read(ctx context.Context, req resource.ReadRequest, re
}
}

// Ensure features and dependent_fields are always set
for i := range newState.Settings.AllFields {
if len(newState.Settings.AllFields[i].Features) == 0 {
newState.Settings.AllFields[i].Features = nil
}
if len(newState.Settings.AllFields[i].DependentFields) == 0 {
newState.Settings.AllFields[i].DependentFields = nil
// marqo doesn't return timeouts, so we maintain the existing state
newState.Timeouts = state.Timeouts

if state.Settings.AllFields == nil {
newState.Settings.AllFields = nil
} else if len(newState.Settings.AllFields) == 0 {
newState.Settings.AllFields = []AllFieldInput{}
} else {
// Ensure features and dependent_fields are always set
for i := range newState.Settings.AllFields {
if len(newState.Settings.AllFields[i].Features) == 0 {
newState.Settings.AllFields[i].Features = nil
}
if len(newState.Settings.AllFields[i].DependentFields) == 0 {
newState.Settings.AllFields[i].DependentFields = nil
}
}
}

Expand All @@ -583,8 +592,11 @@ func (r *indicesResource) Read(ctx context.Context, req resource.ReadRequest, re
newState.Settings.TreatUrlsAndPointersAsMedia = types.BoolNull()
}

// Handle image_preprocessing.patch_method
if newState.Settings.ImagePreprocessing.PatchMethod.ValueString() == "" {
// Handle image_preprocessing
if state.Settings.ImagePreprocessing == nil {
newState.Settings.ImagePreprocessing = nil
} else if newState.Settings.ImagePreprocessing != nil &&
newState.Settings.ImagePreprocessing.PatchMethod.ValueString() == "" {
newState.Settings.ImagePreprocessing.PatchMethod = types.StringNull()
}

Expand All @@ -596,7 +608,7 @@ func (r *indicesResource) Read(ctx context.Context, req resource.ReadRequest, re
newState.Settings.AudioPreprocessing = state.Settings.AudioPreprocessing
}

// Then handle zero values (existing code)
// Then handle zero values
if newState.Settings.VideoPreprocessing != nil &&
newState.Settings.VideoPreprocessing.SplitLength.ValueInt64() == 0 &&
newState.Settings.VideoPreprocessing.SplitOverlap.ValueInt64() == 0 {
Expand Down

0 comments on commit c5005e1

Please sign in to comment.