# How can I add secret to the keystore using API

**URL:** https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532
**Category:** Elasticsearch
**Created:** [July 24, 2021, 1:58pm UTC](https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532 "2021-07-24T13:58:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![idelix](https://avatars.discourse-cdn.com/v4/letter/i/ecd19e/32.png) [@idelix](https://discuss.elastic.co/u/idelix)
#### Post date: [July 24, 2021, 1:58pm UTC](https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532/1 "2021-07-24T13:58:36Z")

</div>

I deployed elastic cloud in Azure and now I'm trying to add keystore secret but not through UI as it will have to be automated in CI/CD.

Could you please advise how this can be achieved via either API or some remote command line tool, I'm currently using terraform provider for ec but doesn't look like it has this option

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [July 25, 2021, 11:30pm UTC](https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532/2 "2021-07-25T23:30:50Z")

</div>

Does [Secure your settings | Elasticsearch Service Documentation | Elastic](https://www.elastic.co/guide/en/cloud/current/ec-configuring-keystore.html) help?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [July 26, 2021, 3:09am UTC](https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532/3 "2021-07-26T03:09:39Z")

</div>

Hi @idelix

There is an issue open for this [here](https://github.com/elastic/terraform-provider-ec/issues/100) perhaps you should add a comment.

Also there is a full REST API and you can add secrets to the keystore with that.

See [Here](https://www.elastic.co/guide/en/cloud/current/ec-restful-api.html) and [Here](https://www.elastic.co/guide/en/cloud/current/definitions.html#KeystoreSecret)

---

<div class="post-metadata">

### Author: ![idelix](https://avatars.discourse-cdn.com/v4/letter/i/ecd19e/32.png) [@idelix](https://discuss.elastic.co/u/idelix)
#### Post date: [July 26, 2021, 6:09am UTC](https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532/4 "2021-07-26T06:09:26Z")

</div>

thanks that did the job for now:

```auto
curl -XPATCH https://api.elastic-cloud.com/api/v1/deployments/$1/elasticsearch/main-elasticsearch/keystore \
-H "Authorization: ApiKey $2" \
-H 'Content-Type: application/json' \
-d '
{
   "secrets" : {
      "<property name>" : {
         "as_file" : false,
         "value" : "'"$3"'"
      }
   }
}
'

```

---

<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 23, 2021, 6:09am UTC](https://discuss.elastic.co/t/how-can-i-add-secret-to-the-keystore-using-api/279532/5 "2021-08-23T06:09:40Z")

</div>

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