Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Elastic Releases Terraform Providers for the Elastic Stack and Elastic Cloud

Elastic Releases Terraform Providers for the Elastic Stack and Elastic Cloud

This item in japanese


Elastic has released their official Terraform provider for configuring the Elastic Stack. The provider enables configuring ElasticSearch, Kibana, Fleet, and other Elastic Stack components. This follows closely on their release of the Elastic Cloud Terraform provider.

The Elastic Stack Terraform provider allows for managed ElasticSearch resources such as index templates, snapshot repositories, snapshot policies, index lifecycle management (ILM) policies, users, and roles. For example, the following Terraform will set up an index named my-index along with two aliases, one of which is a filtered alias. Index settings are also supported such as setting the number of replicas or the idling period.

provider "elasticstack" {
  elasticsearch {}

resource "elasticstack_elasticsearch_index" "my_index" {
  name = "my-index"

  alias {
    name = "my_alias_1"

  alias {
    name = "my_alias_2"
    filter = jsonencode({
      term = { "" = "developer" }

  mappings = jsonencode({
    properties = {
      field1 = { type = "keyword" }
      field2 = { type = "text" }
      field3 = { properties = {
        inner_field1 = { type = "text", index = false }
        inner_field2 = { type = "integer", index = false }
      } }

  settings {
    setting {
      name  = "index.number_of_replicas"
      value = "2"
    setting {
      name  = ""
      value = "20s"

Authentication can be performed via static credentials, environment variables, or the elasticsearch_connection block. For environment variables, ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD, and ELASTICSEARCH_ENDPOINTS are used to specify the username, password, and a comma-separated list of API endpoints.

Elastic also released a Terraform provider for Elastic Cloud which can be used to configure the Elasticsearch Service (ESS), Elastic Cloud Enterprise (ECE), and Elasticsearch Service Private (ESSP). Omer Kushmaro, senior product manager at Elastic, shares that:

This initial provider release allows you to manage and deploy Elastic Cloud deployments, and traffic filters as Terraform resources. It also enables you to query Elastic Cloud APIs as Terraform data sources for the latest available Elastic Stack versions and existing cloud deployments.

For example, the following creates an Elastic Cloud deployment of ElasticSearch and Kibana:

# Create an Elastic Cloud deployment
resource "ec_deployment" "example_minimal" {
  # Optional name.
  name = "my_example_deployment"

  # Mandatory fields
  region                 = "us-east-1"
  version                = data.ec_stack.latest.version
  deployment_template_id = "aws-io-optimized-v2"

  # Use the deployment template defaults
  elasticsearch {}

  kibana {}

The ElasticSearch provider supports Elastic Stack versions from 7.x and up. It is available via GitHub and documentation is available on the Terraform registry. The Elastic Cloud provider is also available via GitHub with documentation on the Terraform registry.

About the Author

Rate this Article