Skip to content

pauldn-wttj/terraform-provider-meilisearch

Repository files navigation

Terraform Provider for Meilisearch.

Release Registry License

This Terraform provider implements resource management for Meilisearch.

Overview

Using the provider

To use this provider, you must install it and provide authentication credentials:

terraform {
  required_providers {
    meilisearch = {
      source = "pauldn-wttj/meilisearch"
      version = "0.0.1"
    }
  }
}

provider "meilisearch" {
  host = "http://localhost:7700"
  api_key = "T35T-M45T3R-K3Y"
}

Alternatively, you may use environment variables MEILISEARCH_API_KEY and / or MEILISEARCH_HOST for authentication. The MEILISEARCH_API_KEY should have admin privileges since it may be used to create all kinds of resources.

Resources

  • meilisearch_api_key: create and manage API keys for Meilisearch.
  • meilisearch_index: create and manage an index in Meilisearch.

Data sources

  • meilisearch_api_key: read API keys for Meilisearch.
  • meilisearch_index: read a Meilisearch index.

Development

This template repository is built on the Terraform Plugin Framework.

Requirements

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go install command:
go install

Adding Dependencies

This provider uses Go modules. Please see the Go documentation for the most up to date information about using Go modules.

To add a new dependency github.com/author/dependency to your Terraform provider:

go get github.com/author/dependency
go mod tidy

Then commit the changes to go.mod and go.sum.

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).

To compile the provider, run go install. This will build the provider and put the provider binary in the $GOPATH/bin directory.

Don't forget that if you want to use a local binary for a Terraform provider, you need to add the following block to your ~/.terraformrc file:

provider_installation {
  dev_overrides {
      "terraform.io/pauldn-wttj/meilisearch" = "<replace/with/your/gopath/bin>"
  }

  direct {}
}

before using it in a .tf file such as:

terraform {
  required_providers {
    meilisearch = {
      source = "terraform.io/pauldn-wttj/meilisearch"
    }
  }
}

To generate or update documentation, run go generate.

In order to run the full suite of Acceptance tests, run make testacc.

make testacc

Tests are run against a Meilisearch Docker container to ease development (see docker_compose/ folder). The task will:

  • Start a Docker container running a Meilisearch instance
  • Seed data on the Meilisearch instance
  • Run Terraform tests from the provider
  • Clean up Docker volume

Run linter

Install golangci-lint and run the linter:

golangci-lint run

Or using Docker:

docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.52.2 golangci-lint run