diff --git a/docs/data-sources/index.md b/docs/data-sources/index.md
new file mode 100644
index 0000000..6af604b
--- /dev/null
+++ b/docs/data-sources/index.md
@@ -0,0 +1,164 @@
+---
+# generated by https://github.com/hashicorp/terraform-plugin-docs
+page_title: "algolia_index Data Source - terraform-provider-algolia"
+subcategory: ""
+description: |-
+ Data source for an index.
+---
+
+# algolia_index (Data Source)
+
+Data source for an index.
+
+## Example Usage
+
+```terraform
+data "algolia_index" "example" {
+ name = "example"
+}
+```
+
+
+## Schema
+
+### Required
+
+- **name** (String) Name of the index.
+
+### Optional
+
+- **id** (String) The ID of this resource.
+
+### Read-Only
+
+- **attributes_config** (List of Object) The configuration for attributes. (see [below for nested schema](#nestedatt--attributes_config))
+- **enable_personalization** (Boolean) Weather to enable the Personalization feature.
+- **enable_rules** (Boolean) Whether Rules should be globally enabled.
+- **faceting_config** (List of Object) The configuration for faceting. (see [below for nested schema](#nestedatt--faceting_config))
+- **highlight_and_snippet_config** (List of Object) The configuration for highlight / snippet in index setting. (see [below for nested schema](#nestedatt--highlight_and_snippet_config))
+- **languages_config** (List of Object) The configuration for languages in index setting. (see [below for nested schema](#nestedatt--languages_config))
+- **pagination_config** (Block List) The configuration for pagination in index setting. (see [below for nested schema](#nestedblock--pagination_config))
+- **performance_config** (List of Object) The configuration for performance in index setting. (see [below for nested schema](#nestedatt--performance_config))
+- **query_strategy_config** (List of Object) The configuration for query strategy in index setting. (see [below for nested schema](#nestedatt--query_strategy_config))
+- **ranking_config** (List of Object) The configuration for ranking. (see [below for nested schema](#nestedatt--ranking_config))
+- **typos_config** (List of Object) The configuration for typos in index setting. (see [below for nested schema](#nestedatt--typos_config))
+
+
+### Nested Schema for `attributes_config`
+
+Read-Only:
+
+- **attributes_for_faceting** (Set of String)
+- **attributes_to_retrieve** (Set of String)
+- **searchable_attributes** (List of String)
+- **unretrievable_attributes** (Set of String)
+
+
+
+### Nested Schema for `faceting_config`
+
+Read-Only:
+
+- **max_values_per_facet** (Number)
+- **sort_facet_values_by** (String)
+
+
+
+### Nested Schema for `highlight_and_snippet_config`
+
+Read-Only:
+
+- **attributes_to_highlight** (Set of String)
+- **attributes_to_snippet** (Set of String)
+- **highlight_post_tag** (String)
+- **highlight_pre_tag** (String)
+- **restrict_highlight_and_snippet_arrays** (Boolean)
+- **snippet_ellipsis_text** (String)
+
+
+
+### Nested Schema for `languages_config`
+
+Read-Only:
+
+- **attributes_to_transliterate** (Set of String)
+- **camel_case_attributes** (Set of String)
+- **custom_normalization** (Map of String)
+- **decompound_query** (Boolean)
+- **decompounded_attributes** (List of Object) (see [below for nested schema](#nestedobjatt--languages_config--decompounded_attributes))
+- **ignore_plurals** (Boolean)
+- **ignore_plurals_for** (Set of String)
+- **index_languages** (Set of String)
+- **keep_diacritics_on_characters** (String)
+- **query_languages** (Set of String)
+- **remove_stop_words** (Boolean)
+- **remove_stop_words_for** (Set of String)
+
+
+### Nested Schema for `languages_config.decompounded_attributes`
+
+Read-Only:
+
+- **attributes** (Set of String)
+- **language** (String)
+
+
+
+
+### Nested Schema for `pagination_config`
+
+Read-Only:
+
+- **hits_per_page** (Number) The number of hits per page.
+- **pagination_limited_to** (Number) The maximum number of hits accessible via pagination
+
+
+
+### Nested Schema for `performance_config`
+
+Read-Only:
+
+- **allow_compression_of_integer_array** (Boolean)
+- **numeric_attributes_for_filtering** (Set of String)
+
+
+
+### Nested Schema for `query_strategy_config`
+
+Read-Only:
+
+- **advanced_syntax** (Boolean)
+- **advanced_syntax_features** (Set of String)
+- **alternatives_as_exact** (Set of String)
+- **disable_exact_on_attributes** (Set of String)
+- **disable_prefix_on_attributes** (Set of String)
+- **exact_on_single_word_query** (String)
+- **optional_words** (Set of String)
+- **query_type** (String)
+- **remove_words_if_no_results** (String)
+
+
+
+### Nested Schema for `ranking_config`
+
+Read-Only:
+
+- **custom_ranking** (List of String)
+- **ranking** (List of String)
+- **replicas** (Set of String)
+
+
+
+### Nested Schema for `typos_config`
+
+Read-Only:
+
+- **allow_typos_on_numeric_tokens** (Boolean)
+- **disable_typo_tolerance_on_attributes** (List of String)
+- **disable_typo_tolerance_on_words** (List of String)
+- **min_word_size_for_1_typo** (Number)
+- **min_word_size_for_2_typos** (Number)
+- **separators_to_index** (String)
+- **typo_tolerance** (String)
+
+
diff --git a/examples/data-sources/algolia_index/data-source.tf b/examples/data-sources/algolia_index/data-source.tf
new file mode 100644
index 0000000..b185bae
--- /dev/null
+++ b/examples/data-sources/algolia_index/data-source.tf
@@ -0,0 +1,3 @@
+data "algolia_index" "example" {
+ name = "example"
+}
diff --git a/internal/provider/data_source_index.go b/internal/provider/data_source_index.go
new file mode 100644
index 0000000..3d7561a
--- /dev/null
+++ b/internal/provider/data_source_index.go
@@ -0,0 +1,424 @@
+package provider
+
+import (
+ "context"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+func dataSourceIndex() *schema.Resource {
+ return &schema.Resource{
+ Description: "Data source for an index.",
+ ReadContext: dataSourceIndexRead,
+ // https://www.algolia.com/doc/api-reference/settings-api-parameters/
+ Schema: map[string]*schema.Schema{
+ "name": {
+ Type: schema.TypeString,
+ Required: true,
+ ForceNew: true,
+ Description: "Name of the index.",
+ },
+ "attributes_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for attributes.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "searchable_attributes": {
+ Type: schema.TypeList,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Computed: true,
+ Description: "The complete list of attributes used for searching.",
+ },
+ "attributes_for_faceting": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "The complete list of attributes that will be used for faceting.",
+ },
+ "unretrievable_attributes": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes that cannot be retrieved at query time.",
+ },
+ "attributes_to_retrieve": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes to be retrieved at query time.",
+ },
+ },
+ },
+ },
+ "ranking_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for ranking.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "ranking": {
+ Type: schema.TypeList,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Computed: true,
+ Description: "List of ranking criteria.",
+ },
+ "custom_ranking": {
+ Type: schema.TypeList,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Computed: true,
+ Description: "List of attributes for custom ranking criterion.",
+ },
+ // TODO: Add after the PR below merged.
+ // https://github.com/algolia/algoliasearch-client-go/pull/661
+ // "relevancy_strictness": {
+ // Type: schema.TypeInt,
+ // Computed: true,
+ // Description: "Relevancy threshold below which less relevant results aren’t included in the results",
+ // },
+ "replicas": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of replica names.",
+ },
+ },
+ },
+ },
+ "faceting_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for faceting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "max_values_per_facet": {
+ Type: schema.TypeInt,
+ Computed: true,
+ Description: "Maximum number of facet values to return for each facet during a regular search.",
+ },
+ "sort_facet_values_by": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "Parameter to controls how the facet values are sorted within each faceted attribute.",
+ },
+ },
+ },
+ },
+ "highlight_and_snippet_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for highlight / snippet in index setting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "attributes_to_highlight": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes to highlight.",
+ },
+ "attributes_to_snippet": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes to snippet, with an optional maximum number of words to snippet.",
+ },
+ "highlight_pre_tag": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "The HTML string to insert before the highlighted parts in all highlight and snippet results.",
+ },
+ "highlight_post_tag": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "The HTML string to insert after the highlighted parts in all highlight and snippet results.",
+ },
+ "snippet_ellipsis_text": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "String used as an ellipsis indicator when a snippet is truncated.",
+ },
+ "restrict_highlight_and_snippet_arrays": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Restrict highlighting and snippeting to items that matched the query.",
+ },
+ },
+ },
+ },
+ "pagination_config": {
+ Type: schema.TypeList,
+ Optional: true,
+ Computed: true,
+ Description: "The configuration for pagination in index setting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "hits_per_page": {
+ Type: schema.TypeInt,
+ Computed: true,
+ Description: "The number of hits per page.",
+ },
+ "pagination_limited_to": {
+ Type: schema.TypeInt,
+ Computed: true,
+ Description: "The maximum number of hits accessible via pagination",
+ },
+ },
+ },
+ },
+ "typos_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for typos in index setting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "min_word_size_for_1_typo": {
+ Type: schema.TypeInt,
+ Computed: true,
+ Description: "Minimum number of characters a word in the query string must contain to accept matches with 1 typo.",
+ },
+ "min_word_size_for_2_typos": {
+ Type: schema.TypeInt,
+ Computed: true,
+ Description: "Minimum number of characters a word in the query string must contain to accept matches with 2 typos.",
+ },
+ "typo_tolerance": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "Whether typo tolerance is enabled and how it is applied",
+ },
+ "allow_typos_on_numeric_tokens": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Whether to allow typos on numbers (“numeric tokens”) in the query str",
+ },
+ "disable_typo_tolerance_on_attributes": {
+ Type: schema.TypeList,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Computed: true,
+ Description: "List of attributes on which you want to disable typo tolerance.",
+ },
+ "disable_typo_tolerance_on_words": {
+ Type: schema.TypeList,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Computed: true,
+ Description: "List of words on which typo tolerance will be disabled.",
+ },
+ "separators_to_index": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "Separators (punctuation characters) to index. By default, separators are not indexed.",
+ },
+ },
+ },
+ },
+ "languages_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for languages in index setting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "ignore_plurals": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Weather to treat singular, plurals, and other forms of declensions as matching terms.",
+ },
+ "ignore_plurals_for": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: `Weather to treat singular, plurals, and other forms of declensions as matching terms in target languages.
+List of supported languages are listed on http://nhttps//www.algolia.com/doc/api-reference/api-parameters/ignorePlurals/#usage-notes`,
+ },
+ "attributes_to_transliterate": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes to apply transliteration",
+ },
+ "remove_stop_words": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Weather to removes stop (common) words from the query before executing it.",
+ },
+ "remove_stop_words_for": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of languages to removes stop (common) words from the query before executing it.",
+ },
+ "camel_case_attributes": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes on which to do a decomposition of camel case words.",
+ },
+ "decompounded_attributes": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "List of attributes to apply word segmentation, also known as decompounding.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "language": {
+ Type: schema.TypeString,
+ Computed: true,
+ },
+ "attributes": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ },
+ },
+ },
+ },
+ "keep_diacritics_on_characters": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "List of characters that the engine shouldn’t automatically normalize.",
+ },
+ "custom_normalization": {
+ Type: schema.TypeMap,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Computed: true,
+ Description: "Custom normalization which overrides the engine’s default normalization",
+ },
+ "query_languages": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of languages to be used by language-specific settings and functionalities such as ignorePlurals, removeStopWords, and CJK word-detection.",
+ },
+ "index_languages": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of languages at the index level for language-specific processing such as tokenization and normalization.",
+ },
+ "decompound_query": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Weather to split compound words into their composing atoms in the query.",
+ },
+ },
+ },
+ },
+ "enable_rules": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Whether Rules should be globally enabled.",
+ },
+ "enable_personalization": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Weather to enable the Personalization feature.",
+ },
+ "query_strategy_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for query strategy in index setting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "query_type": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "Query type to control if and how query words are interpreted as prefixes.",
+ },
+ "remove_words_if_no_results": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "Strategy to remove words from the query when it doesn’t match any hits.",
+ },
+ "advanced_syntax": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Weather to enable the advanced query syntax.",
+ },
+ "optional_words": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "A list of words that should be considered as optional when found in the query.",
+ },
+ "disable_prefix_on_attributes": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes on which you want to disable prefix matching.",
+ },
+ "disable_exact_on_attributes": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of attributes on which you want to disable the exact ranking criterion.",
+ },
+ "exact_on_single_word_query": {
+ Type: schema.TypeString,
+ Computed: true,
+ Description: "Controls how the exact ranking criterion is computed when the query contains only one word.",
+ },
+ "alternatives_as_exact": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of alternatives that should be considered an exact match by the exact ranking criterion.",
+ },
+ "advanced_syntax_features": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "Advanced syntax features to be activated when ‘advancedSyntax’ is enabled",
+ },
+ // TODO: Add params for advanced setting
+ // https://www.algolia.com/doc/api-reference/settings-api-parameters/
+ },
+ },
+ },
+ "performance_config": {
+ Type: schema.TypeList,
+ Computed: true,
+ Description: "The configuration for performance in index setting.",
+ Elem: &schema.Resource{
+ Schema: map[string]*schema.Schema{
+ "numeric_attributes_for_filtering": {
+ Type: schema.TypeSet,
+ Elem: &schema.Schema{Type: schema.TypeString},
+ Set: schema.HashString,
+ Computed: true,
+ Description: "List of numeric attributes that can be used as numerical filters.",
+ },
+ "allow_compression_of_integer_array": {
+ Type: schema.TypeBool,
+ Computed: true,
+ Description: "Weather to enable compression of large integer arrays.",
+ },
+ },
+ },
+ },
+ },
+ }
+}
+
+func dataSourceIndexRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
+ d.SetId(d.Get("name").(string))
+ if err := refreshIndexState(ctx, d, m); err != nil {
+ return diag.FromErr(err)
+ }
+ return nil
+}
diff --git a/internal/provider/data_source_index_test.go b/internal/provider/data_source_index_test.go
new file mode 100644
index 0000000..45de343
--- /dev/null
+++ b/internal/provider/data_source_index_test.go
@@ -0,0 +1,79 @@
+package provider
+
+import (
+ "fmt"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
+ "testing"
+)
+
+func TestAccDataSourceIndex(t *testing.T) {
+ indexName := randStringStartWithAlpha(100)
+ dataSourceName := fmt.Sprintf("data.algolia_index.%s", indexName)
+
+ resource.ParallelTest(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ ProviderFactories: providerFactories,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccDatasourceIndex(indexName),
+ Check: resource.ComposeTestCheckFunc(
+ resource.TestCheckResourceAttr(dataSourceName, "name", indexName),
+ testCheckResourceListAttr(dataSourceName, "attributes_config.0.searchable_attributes", []string{"title", "category,tag", "unordered(description)"}),
+ testCheckResourceListAttr(dataSourceName, "attributes_config.0.attributes_for_faceting", []string{"category"}),
+ testCheckResourceListAttr(dataSourceName, "attributes_config.0.unretrievable_attributes", []string{"author_email"}),
+ testCheckResourceListAttr(dataSourceName, "attributes_config.0.attributes_to_retrieve", []string{"body", "category", "description", "tag", "title"}),
+ testCheckResourceListAttr(dataSourceName, "ranking_config.0.ranking", []string{"words", "proximity"}),
+ resource.TestCheckNoResourceAttr(dataSourceName, "ranking_config.0.replicas.0"),
+ resource.TestCheckResourceAttr(dataSourceName, "faceting_config.0.max_values_per_facet", "50"),
+ resource.TestCheckResourceAttr(dataSourceName, "faceting_config.0.sort_facet_values_by", "alpha"),
+ ),
+ },
+ },
+ })
+}
+
+func testAccDatasourceIndex(name string) string {
+ return `
+resource "algolia_index" "` + name + `" {
+ name = "` + name + `"
+ attributes_config {
+ searchable_attributes = [
+ "title",
+ "category,tag",
+ "unordered(description)",
+ ]
+ attributes_for_faceting = [
+ "category"
+ ]
+ unretrievable_attributes = [
+ "author_email"
+ ]
+ attributes_to_retrieve = [
+ "title",
+ "category",
+ "tag",
+ "description",
+ "body"
+ ]
+ }
+ ranking_config {
+ ranking = [
+ "words",
+ "proximity"
+ ]
+ }
+ faceting_config {
+ max_values_per_facet = 50
+ sort_facet_values_by = "alpha"
+ }
+
+ languages_config {
+ remove_stop_words_for = ["en"]
+ }
+}
+
+data "algolia_index" "` + name + `" {
+ name = algolia_index.` + name + `.name
+}
+`
+}
diff --git a/internal/provider/provider.go b/internal/provider/provider.go
index ba6ca40..871e0ee 100644
--- a/internal/provider/provider.go
+++ b/internal/provider/provider.go
@@ -36,6 +36,9 @@ func New(version string) func() *schema.Provider {
"algolia_rule": resourceRule(),
"algolia_synonyms": resourceSynonyms(),
},
+ DataSourcesMap: map[string]*schema.Resource{
+ "algolia_index": dataSourceIndex(),
+ },
}
p.ConfigureContextFunc = configure(version, p)