1. Packages
  2. Opensearch Provider
  3. API Docs
  4. IndexTemplate
opensearch 2.3.1 published on Monday, Apr 14, 2025 by opensearch-project

opensearch.IndexTemplate

Explore with Pulumi AI

Provides an OpenSearch index template resource.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as opensearch from "@pulumi/opensearch";

// Create an index template
const template1 = new opensearch.IndexTemplate("template1", {body: `{
  "index_patterns": [
    "logs-2020-01-*"
  ],
  "template": {
    "aliases": {
      "my_logs": {}
    },
    "settings": {
      "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1"
      }
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "value": {
          "type": "double"
        }
      }
    }
  }
}

`});
Copy
import pulumi
import pulumi_opensearch as opensearch

# Create an index template
template1 = opensearch.IndexTemplate("template1", body="""{
  "index_patterns": [
    "logs-2020-01-*"
  ],
  "template": {
    "aliases": {
      "my_logs": {}
    },
    "settings": {
      "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1"
      }
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "value": {
          "type": "double"
        }
      }
    }
  }
}

""")
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/opensearch/v2/opensearch"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Create an index template
		_, err := opensearch.NewIndexTemplate(ctx, "template1", &opensearch.IndexTemplateArgs{
			Body: pulumi.String(`{
  "index_patterns": [
    "logs-2020-01-*"
  ],
  "template": {
    "aliases": {
      "my_logs": {}
    },
    "settings": {
      "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1"
      }
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "value": {
          "type": "double"
        }
      }
    }
  }
}

`),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Opensearch = Pulumi.Opensearch;

return await Deployment.RunAsync(() => 
{
    // Create an index template
    var template1 = new Opensearch.IndexTemplate("template1", new()
    {
        Body = @"{
  ""index_patterns"": [
    ""logs-2020-01-*""
  ],
  ""template"": {
    ""aliases"": {
      ""my_logs"": {}
    },
    ""settings"": {
      ""index"": {
        ""number_of_shards"": ""2"",
        ""number_of_replicas"": ""1""
      }
    },
    ""mappings"": {
      ""properties"": {
        ""timestamp"": {
          ""type"": ""date"",
          ""format"": ""yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis""
        },
        ""value"": {
          ""type"": ""double""
        }
      }
    }
  }
}

",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.opensearch.IndexTemplate;
import com.pulumi.opensearch.IndexTemplateArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        // Create an index template
        var template1 = new IndexTemplate("template1", IndexTemplateArgs.builder()
            .body("""
{
  "index_patterns": [
    "logs-2020-01-*"
  ],
  "template": {
    "aliases": {
      "my_logs": {}
    },
    "settings": {
      "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1"
      }
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "value": {
          "type": "double"
        }
      }
    }
  }
}

            """)
            .build());

    }
}
Copy
resources:
  # Create an index template
  template1:
    type: opensearch:IndexTemplate
    properties:
      body: |+
        {
          "index_patterns": [
            "logs-2020-01-*"
          ],
          "template": {
            "aliases": {
              "my_logs": {}
            },
            "settings": {
              "index": {
                "number_of_shards": "2",
                "number_of_replicas": "1"
              }
            },
            "mappings": {
              "properties": {
                "timestamp": {
                  "type": "date",
                  "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                },
                "value": {
                  "type": "double"
                }
              }
            }
          }
        }        
Copy

Create IndexTemplate Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new IndexTemplate(name: string, args: IndexTemplateArgs, opts?: CustomResourceOptions);
@overload
def IndexTemplate(resource_name: str,
                  args: IndexTemplateArgs,
                  opts: Optional[ResourceOptions] = None)

@overload
def IndexTemplate(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  body: Optional[str] = None,
                  index_template_id: Optional[str] = None,
                  name: Optional[str] = None)
func NewIndexTemplate(ctx *Context, name string, args IndexTemplateArgs, opts ...ResourceOption) (*IndexTemplate, error)
public IndexTemplate(string name, IndexTemplateArgs args, CustomResourceOptions? opts = null)
public IndexTemplate(String name, IndexTemplateArgs args)
public IndexTemplate(String name, IndexTemplateArgs args, CustomResourceOptions options)
type: opensearch:IndexTemplate
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. IndexTemplateArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. IndexTemplateArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. IndexTemplateArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. IndexTemplateArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. IndexTemplateArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var indexTemplateResource = new Opensearch.IndexTemplate("indexTemplateResource", new()
{
    Body = "string",
    IndexTemplateId = "string",
    Name = "string",
});
Copy
example, err := opensearch.NewIndexTemplate(ctx, "indexTemplateResource", &opensearch.IndexTemplateArgs{
	Body:            pulumi.String("string"),
	IndexTemplateId: pulumi.String("string"),
	Name:            pulumi.String("string"),
})
Copy
var indexTemplateResource = new IndexTemplate("indexTemplateResource", IndexTemplateArgs.builder()
    .body("string")
    .indexTemplateId("string")
    .name("string")
    .build());
Copy
index_template_resource = opensearch.IndexTemplate("indexTemplateResource",
    body="string",
    index_template_id="string",
    name="string")
Copy
const indexTemplateResource = new opensearch.IndexTemplate("indexTemplateResource", {
    body: "string",
    indexTemplateId: "string",
    name: "string",
});
Copy
type: opensearch:IndexTemplate
properties:
    body: string
    indexTemplateId: string
    name: string
Copy

IndexTemplate Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The IndexTemplate resource accepts the following input properties:

Body This property is required. string
The JSON body of the index template.
IndexTemplateId string
The ID of this resource.
Name string
The name of the index template.
Body This property is required. string
The JSON body of the index template.
IndexTemplateId string
The ID of this resource.
Name string
The name of the index template.
body This property is required. String
The JSON body of the index template.
indexTemplateId String
The ID of this resource.
name String
The name of the index template.
body This property is required. string
The JSON body of the index template.
indexTemplateId string
The ID of this resource.
name string
The name of the index template.
body This property is required. str
The JSON body of the index template.
index_template_id str
The ID of this resource.
name str
The name of the index template.
body This property is required. String
The JSON body of the index template.
indexTemplateId String
The ID of this resource.
name String
The name of the index template.

Outputs

All input properties are implicitly available as output properties. Additionally, the IndexTemplate resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing IndexTemplate Resource

Get an existing IndexTemplate resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: IndexTemplateState, opts?: CustomResourceOptions): IndexTemplate
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        body: Optional[str] = None,
        index_template_id: Optional[str] = None,
        name: Optional[str] = None) -> IndexTemplate
func GetIndexTemplate(ctx *Context, name string, id IDInput, state *IndexTemplateState, opts ...ResourceOption) (*IndexTemplate, error)
public static IndexTemplate Get(string name, Input<string> id, IndexTemplateState? state, CustomResourceOptions? opts = null)
public static IndexTemplate get(String name, Output<String> id, IndexTemplateState state, CustomResourceOptions options)
resources:  _:    type: opensearch:IndexTemplate    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Body string
The JSON body of the index template.
IndexTemplateId string
The ID of this resource.
Name string
The name of the index template.
Body string
The JSON body of the index template.
IndexTemplateId string
The ID of this resource.
Name string
The name of the index template.
body String
The JSON body of the index template.
indexTemplateId String
The ID of this resource.
name String
The name of the index template.
body string
The JSON body of the index template.
indexTemplateId string
The ID of this resource.
name string
The name of the index template.
body str
The JSON body of the index template.
index_template_id str
The ID of this resource.
name str
The name of the index template.
body String
The JSON body of the index template.
indexTemplateId String
The ID of this resource.
name String
The name of the index template.

Import

$ pulumi import opensearch:index/indexTemplate:IndexTemplate template_1 template_1
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
opensearch opensearch-project/terraform-provider-opensearch
License
Notes
This Pulumi package is based on the opensearch Terraform Provider.