in internal/elasticsearch/index/template.go [19:201]
func ResourceTemplate() *schema.Resource {
templateSchema := map[string]*schema.Schema{
"id": {
Description: "Internal identifier of the resource",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the index template to create.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"composed_of": {
Description: "An ordered list of component template names.",
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"data_stream": {
Description: "If this object is included, the template is used to create data streams and their backing indices. Supports an empty object.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"hidden": {
Description: "If true, the data stream is hidden.",
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"allow_custom_routing": {
Description: "If `true`, the data stream supports custom routing. Defaults to `false`. Available only in **8.x**",
Type: schema.TypeBool,
Optional: true,
},
},
},
},
"index_patterns": {
Description: "Array of wildcard (*) expressions used to match the names of data streams and indices during creation.",
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"metadata": {
Description: "Optional user metadata about the index template.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: utils.DiffJsonSuppress,
},
"priority": {
Description: "Priority to determine index template precedence when a new data stream or index is created.",
Type: schema.TypeInt,
ValidateFunc: validation.IntAtLeast(0),
Optional: true,
},
"template": {
Description: "Template to be applied. It may optionally include an aliases, mappings, lifecycle, or settings configuration.",
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"alias": {
Description: "Alias to add.",
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Description: "The alias name.",
Type: schema.TypeString,
Required: true,
},
"filter": {
Description: "Query used to limit documents the alias can access.",
Type: schema.TypeString,
Optional: true,
Default: "",
DiffSuppressFunc: utils.DiffJsonSuppress,
ValidateFunc: validation.StringIsJSON,
},
"index_routing": {
Description: "Value used to route indexing operations to a specific shard. If specified, this overwrites the `routing` value for indexing operations.",
Type: schema.TypeString,
Optional: true,
Default: "",
},
"is_hidden": {
Description: "If true, the alias is hidden.",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"is_write_index": {
Description: "If true, the index is the write index for the alias.",
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"routing": {
Description: "Value used to route indexing and search operations to a specific shard.",
Type: schema.TypeString,
Optional: true,
Default: "",
},
"search_routing": {
Description: "Value used to route search operations to a specific shard. If specified, this overwrites the routing value for search operations.",
Type: schema.TypeString,
Optional: true,
Default: "",
},
},
},
},
"mappings": {
Description: "Mapping for fields in the index. Should be specified as a JSON object of field mappings. See the documentation (https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html) for more details",
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: utils.DiffJsonSuppress,
ValidateFunc: validation.All(
validation.StringIsJSON, stringIsJSONObject,
),
},
"settings": {
Description: "Configuration options for the index. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-modules-settings",
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: utils.DiffIndexSettingSuppress,
ValidateFunc: validation.All(
validation.StringIsJSON, stringIsJSONObject,
),
},
"lifecycle": {
Description: "Lifecycle of data stream. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-lifecycle.html",
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data_retention": {
Description: "The retention period of the data indexed in this data stream.",
Type: schema.TypeString,
Required: true,
},
},
},
},
},
},
},
"version": {
Description: "Version number used to manage index templates externally.",
Type: schema.TypeInt,
Optional: true,
},
}
utils.AddConnectionSchema(templateSchema)
return &schema.Resource{
Description: "Creates or updates an index template. Index templates define settings, mappings, and aliases that can be applied automatically to new indices. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-template.html",
CreateContext: resourceIndexTemplatePut,
UpdateContext: resourceIndexTemplatePut,
ReadContext: resourceIndexTemplateRead,
DeleteContext: resourceIndexTemplateDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: templateSchema,
}
}