Terraform Provider for Algolia.
Fork notice. This is the Flaconi/terraform-provider-algolia fork of k-yomo/terraform-provider-algolia, upgraded to use
algoliasearch-client-gov4 (the upstream main branch is still on v3). See Fork differences below.
Full, comprehensive documentation for the underlying provider schema is available on the Terraform website:
https://registry.terraform.io/providers/k-yomo/algolia/latest/docs
The schema in this fork is API-compatible with upstream; the Algolia SDK upgrade is internal.
The provider authenticates against Algolia using two values:
| Env var | Description |
|---|---|
ALGOLIA_APP_ID |
Your Algolia application ID (10-character string from the dashboard). Required. Can also be set via the app_id provider attribute. |
ALGOLIA_API_KEY |
An Algolia Admin API Key. Required. A search-only or scoped key will fail on most resources. Can also be set via the api_key provider attribute. |
$ export ALGOLIA_APP_ID=<your app id>
$ export ALGOLIA_API_KEY=<your admin api key>The example below demonstrates the following operations:
- create index
- create rule for the index
- create api key to search the index
terraform {
required_providers {
algolia = {
source = "Flaconi/algolia"
version = ">= 0.1.0, < 1.0.0"
}
}
}
provider "algolia" {
app_id = "XXXXXXXXXX"
}
resource "algolia_index" "example" {
name = "example"
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"]
}
}
resource "algolia_rule" "example" {
index_name = algolia_index.example.name
object_id = "example-rule"
conditions {
pattern = "{facet:category}"
anchoring = "contains"
}
consequence {
params_json = jsonencode({
automaticFacetFilters = [
{
facet = "category"
disjunctive = true
score = 0
}
]
})
}
}
resource "algolia_api_key" "example" {
acl = [
"search",
"browse"
]
expires_at = "2030-01-01T00:00:00Z"
max_hits_per_query = 100
max_queries_per_ip_per_hour = 10000
description = "This is a example api key"
indexes = [algolia_index.example.name]
referers = ["https://algolia.com/\\*"]
}This fork tracks k-yomo/terraform-provider-algolia but adds:
- Algolia Go client upgraded to v4 (
algoliasearch-client-go/v4). Upstream main is still on v3; upstream's PR #269 attempts the v4 upgrade but has failing CI and has not been merged. - Read normalization for v4's response shape. The v4 SDK returns
nilfor fields at server-side defaults, which would otherwise produce permanent plan diffs. The provider now substitutes the documented defaults (["*"]forattributes_to_retrieve,"…"forsnippet_ellipsis_text,100forrelevancy_strictness,10formax_facet_hits, etc.). - Last-replica detach fix. When deleting the only replica of a primary, the old code passed a
nilslice toSetSettings, which v4'somitempty-awareMarshalJSONthen omitted entirely — so the replicas list was never updated andDeleteIndexfailed with 403. Fixed to always send an explicit empty array. - Replica detach propagation poll. After clearing the primary's replicas list, the provider now polls the replica's
primarysetting until the detachment has propagated server-side before issuingDeleteIndex. - API key Create/Update wait workarounds. The v4 SDK's
WaitForApiKey(ADD)treats 403 propagation responses as success (premature exit), andWaitForApiKey(UPDATE)compares the ticking-downValidityfield (never matches). The provider replaces both with its own polling loop. - Rule condition
contextempty-string fix. v4's API rejects emptycontextvalues against the regex[A-Za-z0-9_-]+. The provider no longer sends a pointer-to-empty-string when the field is unset. - Query suggestions idempotent delete. Algolia auto-deletes the query-suggestions config when its source index is deleted, so
DeleteConfigreturning 404 is now treated as success. - Unified
IsNotFoundErroracross the search and query-suggestions client error types.
I appreciate your help!
To contribute, please read the Contributing to Terraform - Algolia Provider
ManoMano