# Create an index with 0 replicas using terraform

**URL:** <https://discuss.elastic.co/t/create-an-index-with-0-replicas-using-terraform/324707>\
**Category:** Elasticsearch\
**Created:** [February 4, 2023, 10:05am UTC](https://discuss.elastic.co/t/create-an-index-with-0-replicas-using-terraform/324707 "2023-02-04T10:05:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![james-world](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@james-world](https://discuss.elastic.co/u/james-world)\
**Post date:** [February 4, 2023, 10:05am UTC](https://discuss.elastic.co/t/create-an-index-with-0-replicas-using-terraform/324707/1 "2023-02-04T10:05:32Z")

</div>

I am trying to use [the latest terraform provider, currently 0.5.0](https://registry.terraform.io/providers/elastic/elasticstack/latest/docs/resources/elasticsearch_index) to create an index with no replicas into an existing Azure managed deployment.

I can successfully create the index, but I always get 1 replica, even though I am setting `number_of_replicas` to 0.

Does anyone have an idea if I am doing something wrong or the provider is at fault?

The terraform is very simple - like the example below _(I've hidden the name and mappings details)_:

```auto
resource "elasticstack_elasticsearch_index" "test_index" {
  name = ...
  mappings = ...

  number_of_shards = 1
  number_of_replicas = 0

}

```

---

<div class="post-metadata">

**Author:** ![Wave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wave/32/117242_2.png) [@Wave](https://discuss.elastic.co/u/Wave)\
**Post date:** [February 8, 2023, 7:47pm UTC](https://discuss.elastic.co/t/create-an-index-with-0-replicas-using-terraform/324707/2 "2023-02-08T19:47:32Z")

</div>

Not familiar with terraform, but you should be able to create an index template (in elastic through kibana) where you can specify that any index (ex: test\_index\*) by default has 1 primary and 0 replicas. My guess is you then wouldn't have to specify that in terraform. Hope that helps.

---

<div class="post-metadata">

**Author:** ![james-world](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@james-world](https://discuss.elastic.co/u/james-world)\
**Post date:** [February 9, 2023, 11:42pm UTC](https://discuss.elastic.co/t/create-an-index-with-0-replicas-using-terraform/324707/3 "2023-02-09T23:42:26Z")

</div>

Hi Andrew - thanks for the suggestion. I guess that would probably work and would be a workaround - but it's a bit hacky. Looks like this is a known bug in the provider - also it seems to have been reported and close although it's not fixed. See [here](https://github.com/elastic/terraform-provider-elasticstack/issues/238).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 9, 2023, 11:43pm UTC](https://discuss.elastic.co/t/create-an-index-with-0-replicas-using-terraform/324707/4 "2023-03-09T23:43:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
