Introduction
When managing Amazon OpenSearch Service with Terraform, you may encounter an error in the AWS Console when viewing indexes created by a different IAM identity. This article explains the cause of this error and how to resolve it by correctly configuring access policies.
Problem
After using Terraform to provision Amazon OpenSearch resources, when you view the service in the AWS Management Console, the Indexes tab may display dashes (-) instead of the index names. Additionally, the web interface presents the following error message:
e.map is not a function
Cause
This issue is caused by a mismatch in IAM identities. The error occurs when the IAM identity (user or role) used to create the OpenSearch resources with Terraform is different from the IAM identity being used to access the AWS Management Console.
The OpenSearch access policy restricts service access by default to the principal that created the resource. If your console user is not explicitly granted access in the policy, the service cannot correctly display the index information, leading to the error.
Solution
To resolve this issue, you must amend the data access policy to grant permissions to all principals that require access, including any IAM users or roles that will view the resources in the AWS Console.
- Identify all IAM principals (users and roles) that need to access the OpenSearch collection through the AWS Console.
- Update your Terraform configuration to include an
aws_opensearchserverless_access_policyresource. This resource should define a policy that adds the necessary principals alongside the principal used by Terraform.
By explicitly defining all required principals in the access policy, you ensure that both Terraform and console users have the appropriate permissions to manage and view the OpenSearch resources, which resolves the e.map is not a function error.
Additional Information
- The OpenSearch service is a fork of Elasticsearch and Kibana maintained by AWS. You can read more about the license change that led to this fork on the Elastic licensing FAQ.
- Terraform can provision OpenSearch resources such as the
aws_opensearchserverless_collection. - To interact with the OpenSearch data plane, you can use the third-party
opensearchprovider. Note that this provider is not developed or supported by HashiCorp.