# How to pin elasticsearch version using “ec” Terraform provider?

**URL:** <https://discuss.elastic.co/t/how-to-pin-elasticsearch-version-using-ec-terraform-provider/307812>\
**Category:** Elasticsearch\
**Created:** [June 21, 2022, 11:38pm UTC](https://discuss.elastic.co/t/how-to-pin-elasticsearch-version-using-ec-terraform-provider/307812 "2022-06-21T23:38:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amruth](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@amruth](https://discuss.elastic.co/u/amruth)\
**Post date:** [June 21, 2022, 11:38pm UTC](https://discuss.elastic.co/t/how-to-pin-elasticsearch-version-using-ec-terraform-provider/307812/1 "2022-06-21T23:38:57Z")

</div>

Hello Everyone, how to pin elasticsearch version using “ec” Terraform provider? I am using the following

> data "ec\_stack" "latest" {  
> version\_regex = "8.2.1"  
> region = var.region  
> }

but it throws “Error: failed to obtain a stack version matching “8.2.1": please specify a valid version\_regex” error. How to solve this issue?

---

<div class="post-metadata">

**Author:** ![Swissmountain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/swissmountain/32/108071_2.png) [@Swissmountain](https://discuss.elastic.co/u/Swissmountain)\
**Post date:** [July 19, 2022, 6:41am UTC](https://discuss.elastic.co/t/how-to-pin-elasticsearch-version-using-ec-terraform-provider/307812/2 "2022-07-19T06:41:47Z")

</div>

According to the official documentation, you can either specify a "valid" version (but which could become invalid when the version is no longer available) or a "regex" for the version that can match a whole minor release list.  
[ec\_stack | Data Sources | elastic/ec | Terraform Registry](https://registry.terraform.io/providers/elastic/ec/latest/docs/data-sources/ec_stack)  
In your case,

```auto
data "ec_stack" "latest" {
version_regex = "8.2.?"
region = var.region
}

```

will give your version 8.2.3 today.

---

<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:** [August 16, 2022, 6:42am UTC](https://discuss.elastic.co/t/how-to-pin-elasticsearch-version-using-ec-terraform-provider/307812/3 "2022-08-16T06:42:04Z")

</div>

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