# Unable to Authenticate using api key with elasticstack Terraform provider

**URL:** <https://discuss.elastic.co/t/unable-to-authenticate-using-api-key-with-elasticstack-terraform-provider/353912>\
**Category:** Terraform\
**Created:** [February 22, 2024, 6:55pm UTC](https://discuss.elastic.co/t/unable-to-authenticate-using-api-key-with-elasticstack-terraform-provider/353912 "2024-02-22T18:55:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Thompson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_thompson/32/125622_2.png) [@Andrew\_Thompson](https://discuss.elastic.co/u/Andrew_Thompson)\
**Post date:** [February 22, 2024, 6:55pm UTC](https://discuss.elastic.co/t/unable-to-authenticate-using-api-key-with-elasticstack-terraform-provider/353912/1 "2024-02-22T18:55:13Z")

</div>

I am attempting to create an agent profile using the elastic/elasticstack terraform provider, which provides resource elasticstack\_fleet\_agent\_policy.

Attempting to use this resource results in an HTTP 401 error. I have created the required api key and I am able to create the agent policy using the API.

I have specified an elasticstack provider and defined the api\_key and endpoints but I am still seeing the HTTP 401 errors

```auto
provider "elasticstack" {
  kibana {
   api_key = "api_key_snipped"
    endpoints = ["https://snipped.gcp.elastic-cloud.com:9243"]

  }
}

```

Has anyone else seen similar?
