### Run Developer Sandbox Setup Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/README.md Execute this command to start OpenSearch and Dashboards, build the provider, and apply the sandbox configuration. ```shell make dev ``` -------------------------------- ### Manual Acceptance Test Setup Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/README.md Manually set up and run acceptance tests without using the Makefile. This involves starting OpenSearch via Docker Compose, setting environment variables for the cluster URL and logging, and then executing the tests. ```sh export OSS_IMAGE="opensearchproject/opensearch:2" docker compose up -d docker compose ps -a # Checks that the process is running # Before OS 2.12.0 # export OPENSEARCH_URL=http://admin:admin@localhost:9200 export OPENSEARCH_URL=http://admin:myStrongPassword123%40456@localhost:9200 export TF_LOG=INFO TF_ACC=1 go test ./... -v -parallel 20 -cover -short ``` -------------------------------- ### Clone and Apply Terraform Example Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/examples/README.md Instructions for cloning the repository and applying a Terraform configuration for an example. Ensure you navigate to the specific example directory before running 'terraform apply'. ```sh $ git clone https://github.com/opensearch-project/terraform-provider-opensearch $ cd terraform-provider-opensearch/examples/ingest_pipeline $ terraform apply ... ``` -------------------------------- ### Generate Documentation Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/README.md Run this command to generate example usage documentation from resource configurations. ```shell make docs ``` -------------------------------- ### Start Debuggable Provider Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/README.md Build the provider executable and start it in debug mode. This is useful for debugging provider logic. ```console $ go build $ ./terraform-provider-opensearch -debuggable # or start in debug mode in your IDE ``` -------------------------------- ### Create a Full User, Role, and Role Mapping Example Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/user.md This example demonstrates the creation of an OpenSearch role, a user, and then maps the user to that role. This is useful for defining granular access control within OpenSearch. The user's password can be provided via a variable. ```terraform resource "opensearch_role" "reader" { role_name = "app_reader" description = "App Reader Role" index_permissions { index_patterns = ["app-*"] allowed_actions = ["get", "read", "search"] } } resource "opensearch_user" "reader" { username = "app-reader" password = var.password } resource "opensearch_roles_mapping" "reader" { role_name = opensearch_role.reader.id description = "App Reader Role" users = [opensearch_user.reader.id] } ``` -------------------------------- ### Basic opensearch_cluster_settings Resource Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/cluster_settings.md Example of how to configure cluster-wide settings like maximum shards per node and index auto-creation patterns. ```terraform resource "opensearch_cluster_settings" "global" { cluster_max_shards_per_node = 10 action_auto_create_index = "my-index-000001,index10,-index1*,+ind*" } ``` -------------------------------- ### Create an OpenSearch index with aliases Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/index.md This example demonstrates creating an OpenSearch index with a specific alias and defining its mappings and shard/replica configuration using JSON encoding. ```terraform resource "opensearch_index" "index" { name = "sample" aliases = jsonencode( { "log": { "is_write_index": true } } ) number_of_replicas = "1" number_of_shards = "1" mappings = jsonencode({ "properties": { "age": { "type": "integer" } } }) } ``` -------------------------------- ### Minimal ML Connector with 'http' protocol Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/ml_connector.md This example shows a minimal ML Connector configuration using the 'http' protocol to connect to OpenAI with an API Key. ```APIDOC ## opensearch_ml_connector.minimal_http ### Description Minimal ML Connector with only the mandatory attributes connecting to OpenAI with an API Key. ### Attributes * `name` (Required) - Name of the ML connector. * `description` (Optional) - Description of the ML connector. * `version` (Required) - Version of the ML connector. * `protocol` (Required) - The protocol to use for the connection (e.g., "aws_sigv4", "http"). * `credential` (Required) - Authentication credentials for the connector. * `openAIKey` (Required for http protocol with OpenAI) * `parameters` (Required) - Parameters specific to the protocol and service. * `endpoint` (Required for http protocol) - The API endpoint. * `max_tokens` (Optional) - Maximum tokens for the completion. * `temperature` (Optional) - Temperature for the completion. * `model` (Optional) - The model to use for completion. * `actions` (Required) - Defines the actions the connector can perform. * `action_type` (Required) - Type of action (e.g., "predict"). * `method` (Required) - HTTP method for the action (e.g., "POST"). * `url` (Required) - URL for the action endpoint. * `headers` (Optional) - HTTP headers for the request. * `request_body` (Optional) - Request body template. * `pre_process_function` (Optional) - Function to pre-process the request. * `post_process_function` (Optional) - Function to post-process the response. ### Example ```terraform resource "opensearch_ml_connector" "minimal_http" { name = "minimal_http" description = "Minimal ML Connector with only the mandatory attributes connecting to OpenAI with an API Key" version = "1" protocol = "http" credential = { openAIKey = "" } parameters = { endpoint = "api.openai.com" max_tokens = 7 temperature = 0 model = "gpt-4.1" } actions { action_type = "predict" method = "POST" url = "https://$${parameters.endpoint}/v1/completions" headers = { Authorization = "Bearer $${credential.openAIKey}" } request_body = "{ \"model\": \"$${parameters.model}\", \"prompt\": \"$${parameters.prompt}\", \"max_tokens\": \"$${parameters.max_tokens}\", \"temperature\": \"$${parameters.temperature}\" }" } } ``` ``` -------------------------------- ### ML Connector with Pre and Post processing functions Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/ml_connector.md This example shows an ML Connector configuration that includes pre-processing and post-processing functions for request and response handling. ```APIDOC ## opensearch_ml_connector.with_pre_post_processing ### Description ML Connector pre and post processing functions. ### Attributes * `name` (Required) - Name of the ML connector. * `description` (Optional) - Description of the ML connector. * `version` (Required) - Version of the ML connector. * `protocol` (Required) - The protocol to use for the connection (e.g., "aws_sigv4", "http"). * `credential` (Required) - Authentication credentials for the connector. * `roleArn` (Required for IAM Role assumption) - ARN of the IAM Role. * `access_key` (Required for direct credentials) - AWS access key. * `secret_key` (Required for direct credentials) - AWS secret key. * `session_token` (Required for direct credentials) - AWS session token. * `parameters` (Required) - Parameters specific to the protocol and service. * `region` (Required for aws_sigv4) - AWS region. * `service_name` (Required for aws_sigv4) - AWS service name. * `actions` (Required) - Defines the actions the connector can perform. * `action_type` (Required) - Type of action (e.g., "predict"). * `method` (Required) - HTTP method for the action (e.g., "POST"). * `url` (Required) - URL for the action endpoint. * `headers` (Optional) - HTTP headers for the request. * `request_body` (Optional) - Request body template. * `pre_process_function` (Optional) - Function to pre-process the request. * `post_process_function` (Optional) - Function to post-process the response. ### Example ```terraform resource "opensearch_ml_connector" "with_pre_post_processing" { name = "with_pre_post_processing" description = "ML Connector pre and post processing functions" version = "1" protocol = "aws_sigv4" credential = { roleArn = "" } parameters = { region = "eu-west-3" service_name = "bedrock" } actions { action_type = "predict" method = "POST" url = "https://bedrock-runtime.$${parameters.region}.amazonaws.com/model/amazon.titan-embed-text-v2:0/invoke" headers = { Content-Type = "application/json" x-amz-content-sha256 = "required" } request_body = "{ \"inputText\": \"$${parameters.inputText}\" }" pre_process_function = "connector.pre_process.bedrock.embedding" post_process_function = "connector.post_process.bedrock.embedding" } } ``` ``` -------------------------------- ### Create a Data Stream Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/data_stream.md This example shows how to create a data stream named 'foo-data-stream'. It depends on a composable index template 'foo-template' which defines the index pattern and enables data stream support. ```terraform resource "opensearch_composable_index_template" "foo" { name = "foo-template" body = < 0", "lang" : "painless" } }, "actions" : [ { "name" : "Slack", "destination_id" : "${opensearch_channel_configuration.slack_on_call_channel.id}", "message_template" : { "source" : "bogus", "lang" : "mustache" }, "throttle_enabled" : false, "subject_template" : { "source" : "Production Errors", "lang" : "mustache" } } ] } ] } EOF } ``` -------------------------------- ### Create an OpenSearch Channel Configuration Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/channel_configuration.md Use this resource to create a new channel configuration in OpenSearch. Ensure the `body` contains a valid JSON object with the desired configuration details, including `config_id`, `name`, `description`, `config_type`, and specific channel settings like `slack.url`. ```terraform resource "opensearch_channel_configuration" "configuration_1" { body = < ``` -------------------------------- ### Create an index template Source: https://github.com/opensearch-project/terraform-provider-opensearch/blob/main/docs/resources/index_template.md Use this resource to create a new index template in OpenSearch. Specify the template name and the JSON body defining index patterns, mappings, settings, and aliases. ```terraform resource "opensearch_index_template" "template_1" { name = "template_1" body = <