Unable to Authenticate using api key with elasticstack Terraform provider

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

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


Has anyone else seen similar?