k-yomo / terraform-provider-algolia

Terraform Provider for Algolia
https://registry.terraform.io/providers/k-yomo/algolia/latest/docs
Mozilla Public License 2.0
37 stars 6 forks source link

Cannot terraform rule "An argument named "facetFilters" is not expected here." #208

Closed greg0ire closed 7 months ago

greg0ire commented 7 months ago

Terraform Version

Affected Resource(s)

Terraform Configuration Files

Copy-paste your Terraform configurations here

resource "algolia_rule" "brand-name" {
  index_name = var.index_name
  object_id  = "remove-laser"

  conditions {
    anchoring    = "is"
    pattern      = "laser"
    alternatives = false
  }

  consequence {
    params {
      facetFilters = ["brand_name:-Laser"]
    }
  }

  description = "Removes all records with the brand name Laser from searches for laser"
}

Expected Behavior

The docs say this about params:

Additional search parameters. Any valid search parameter is allowed. Specific treatment is applied to these fields: query, automaticFacetFilters, automaticOptionalFacetFilters

facetFilters is definitely a valid search parameter: https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/

A rule looking like this should be terraformed:

{
  "condition": {
    "anchoring": "is",
    "pattern": "laser",
    "alternatives": false
  },
  "consequence": {
    "params": {
      "facetFilters": [
        "brand_name:-Laser"
      ]
    }
  },
  "description": "Removes all records with the brand name Laser from searches for laser",
  "objectID": "remove-laser"
}

Actual Behavior

I'm getting an error saying

An argument named "facetFilters" is not expected here.

Steps to Reproduce

Run terraform plan with the above

Important Factoids

None

References

None

k-yomo commented 7 months ago

@greg0ire Oh you're right. It seems we should change the type of params to either JSON string or map to fix the problem and be more flexible.

k-yomo commented 7 months ago

@greg0ire Instead of changing type of params, I introduced new field params_json for backward compatibility. https://github.com/k-yomo/terraform-provider-algolia/pull/210

You can pass json or use terraform map. https://github.com/k-yomo/terraform-provider-algolia/blob/main/examples/resources/algolia_rule/resource.tf

greg0ire commented 7 months ago

Thank you! Will try that next week!