RousselTMLEARNING

Article · Elasticsearch: from discovery to expertise

Automation and infrastructure as code

1. Everything goes through the API #

So everything can be automated.

Principle #

Configuration as code for Elasticsearch

Templates, ILM and SLM policies, ingest pipelines, roles and API keys are API calls: describing them in code lets you review them, test them and rebuild a cluster identically.

2. Terraform #

The elasticstack provider.

Example #

terraform {
  required_providers { elasticstack = { source = "elastic/elasticstack" } }
}
provider "elasticstack" {
  elasticsearch {
    endpoints = ["https://es01:9200"]
    api_key   = var.es_api_key
  }
}

resource "elasticstack_elasticsearch_index_lifecycle" "logs_30d" {
  name = "logs-30d"
  hot {
    rollover { max_primary_shard_size = "50gb", max_age = "1d" }
  }
  delete {
    min_age = "30d"
    delete {}
  }
}

resource "elasticstack_elasticsearch_index_template" "nginx" {
  name           = "logs-nginx"
  index_patterns = ["logs-nginx-*"]
  priority       = 200
  data_stream {}
  template {
    settings = jsonencode({ "index.lifecycle.name" = elasticstack_elasticsearch_index_lifecycle.logs_30d.name })
  }
}
Common mistake: An object changed by hand in Kibana or through the API will be overwritten at the next terraform apply: document that the code is the source of truth and restrict manual write permissions in production.

3. Ansible and CI/CD #

Installing and deploying.

Practices #

  • Ansible to install and configure nodes (packages, elasticsearch.yml, JVM, certificates) with node-by-node restarts.
  • On Kubernetes, ECK + GitOps (Argo CD, Flux): the cluster manifest lives in Git.
  • In CI: validate templates on an ephemeral cluster (container), simulate pipelines (_simulate), then apply.
  • Query non-regression tests (expected results) protect relevance during mapping changes.

📄 Automation and infrastructure as code for Elasticsearch: API, Terraform, Ansible and CI/CD →

My progress

  • ⏱ Estimated time : ≈ 6 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Recent discussions about this course

Ask a question about this lesson →See all discussions about this course

Course Glossary

RBAC (Role-Based Access Control)

An access control method where permissions are assigned to specific roles (e.g., admin, reader) rather than directly to individual users.

Authentication

The process of verifying the identity of a user or system (e.g., login/password, tokens, biometrics).

Authorization

The process that occurs after authentication to determine if the entity has the necessary rights and privileges to access a resource.

API Key

A unique alphanumeric code used to identify, authenticate, and authorize access to an Application Programming Interface (API).

Architecture

The overall structural design of an IT system, defining its various components, their relationships, and the principles guiding its evolution.

Repository

A centralized storage location. This can refer to a source code repository (e.g., Git) or an artifact and binary repository (e.g., Harbor, Nexus, Arti...

Elasticsearch

A distributed, RESTful search and analytics engine capable of addressing a growing number of use cases, built on Apache Lucene.

Recommended Articles

Elasticsearch on Kubernetes with ECK: deployment, persistent storage and upgrades

Deploy Elasticsearch and Kibana on Kubernetes with Elastic Cloud on Kubernetes (ECK): operator, E...

Bindplane in production: high availability, security, Kubernetes and configuration as code

Operate Bindplane in production: active-active servers, PostgreSQL and event bus, TLS for OpAMP, ...

Elasticsearch ingestion: Bulk API, ingest pipelines, enrich and reindex

Ingest and transform data in Elasticsearch: Bulk API, ingest pipelines and processors (grok, diss...

Testing and securing Terraform: validate, terraform test, tflint, Checkov and policies

Ensure the quality of Terraform code: fmt and validate, native terraform test tests with mocked p...

Elasticsearch monitoring and troubleshooting: health, unassigned shards, JVM, hot threads and slow logs

Diagnose an Elasticsearch cluster: cluster health and CAT APIs, unassigned shards and allocation ...

Advanced Elasticsearch security: TLS, certificates, API keys, FLS, DLS and audit

Secure Elasticsearch in depth: transport and HTTP TLS, certificate management with elasticsearch-...

Synthetic monitoring as code: industrializing synthetic scenario management

Learn how to integrate synthetic monitoring into your CI/CD pipelines for automated, resilient pe...

Transforms and enrich: summarising and enriching data in Elasticsearch

Build entity-centric indices with pivot and latest transforms, and enrich documents at ingest tim...

Elasticsearch distributed architecture: node roles, shards, replicas and allocation

Understand how Elasticsearch works as a distributed system: node roles, master nodes and quorum, ...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!