Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Add `elasticstack_elasticsearch_ingest_processor_reroute` data source ([#678](https://github.com/elastic/terraform-provider-elasticstack/issues/678))
- Add support for `supports_agentless` to `elasticstack_fleet_agent_policy` ([#1197](https://github.com/elastic/terraform-provider-elasticstack/pull/1197))
- Ignore `master_timeout` when targeting Serverless projects ([#1207](https://github.com/elastic/terraform-provider-elasticstack/pull/1207))
- Add `ignore_missing_component_templates` to `elasticstack_elasticsearch_index_template` ([#1206](https://github.com/elastic/terraform-provider-elasticstack/pull/1206))

## [0.11.16] - 2025-07-09

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/elasticsearch_index_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ output "template" {
- `composed_of` (List of String) An ordered list of component template names.
- `data_stream` (List of Object) If this object is included, the template is used to create data streams and their backing indices. Supports an empty object. (see [below for nested schema](#nestedatt--data_stream))
- `id` (String) Internal identifier of the resource
- `ignore_missing_component_templates` (List of String) A list of component template names that are ignored if missing.
- `index_patterns` (Set of String) Array of wildcard (*) expressions used to match the names of data streams and indices during creation.
- `metadata` (String) Optional user metadata about the index template.
- `priority` (Number) Priority to determine index template precedence when a new data stream or index is created.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/elasticsearch_index_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "elasticstack_elasticsearch_index_template" "my_data_stream" {
- `composed_of` (List of String) An ordered list of component template names.
- `data_stream` (Block List, Max: 1) If this object is included, the template is used to create data streams and their backing indices. Supports an empty object. (see [below for nested schema](#nestedblock--data_stream))
- `elasticsearch_connection` (Block List, Max: 1, Deprecated) Elasticsearch connection configuration block. This property will be removed in a future provider version. Configure the Elasticsearch connection via the provider configuration instead. (see [below for nested schema](#nestedblock--elasticsearch_connection))
- `ignore_missing_component_templates` (List of String) A list of component template names that are ignored if missing.
- `metadata` (String) Optional user metadata about the index template.
- `priority` (Number) Priority to determine index template precedence when a new data stream or index is created.
- `template` (Block List, Max: 1) Template to be applied. It may optionally include an aliases, mappings, lifecycle, or settings configuration. (see [below for nested schema](#nestedblock--template))
Expand Down
20 changes: 20 additions & 0 deletions internal/elasticsearch/index/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func ResourceTemplate() *schema.Resource {
Type: schema.TypeString,
},
},
"ignore_missing_component_templates": {
Description: "A list of component template names that are ignored if missing.",
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,
Expand Down Expand Up @@ -221,6 +230,14 @@ func resourceIndexTemplatePut(ctx context.Context, d *schema.ResourceData, meta
}
indexTemplate.ComposedOf = compsOf

compsOfIgnore := make([]string, 0)
if v, ok := d.GetOk("ignore_missing_component_templates"); ok {
for _, c := range v.([]interface{}) {
compsOfIgnore = append(compsOfIgnore, c.(string))
}
}
indexTemplate.IgnoreMissingComponentTemplates = compsOfIgnore

if v, ok := d.GetOk("data_stream"); ok {
// 8.x workaround
hasAllowCustomRouting := false
Expand Down Expand Up @@ -371,6 +388,9 @@ func resourceIndexTemplateRead(ctx context.Context, d *schema.ResourceData, meta
if err := d.Set("composed_of", tpl.IndexTemplate.ComposedOf); err != nil {
return diag.FromErr(err)
}
if err := d.Set("ignore_missing_component_templates", tpl.IndexTemplate.IgnoreMissingComponentTemplates); err != nil {
return diag.FromErr(err)
}
if stream := tpl.IndexTemplate.DataStream; stream != nil {
ds := make([]interface{}, 1)
dSettings := make(map[string]interface{})
Expand Down
8 changes: 8 additions & 0 deletions internal/elasticsearch/index/template_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func DataSourceTemplate() *schema.Resource {
Type: schema.TypeString,
},
},
"ignore_missing_component_templates": {
Description: "A list of component template names that are ignored if missing.",
Type: schema.TypeList,
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,
Expand Down
7 changes: 6 additions & 1 deletion internal/elasticsearch/index/template_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestAccIndexTemplateDataSource(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_index_template.test", "name", templateName),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_index_template.test", "index_patterns.*", fmt.Sprintf("tf-acc-%s-*", templateName)),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_index_template.test", "composed_of.*", fmt.Sprintf("%s-logs@custom", templateName)),
resource.TestCheckTypeSetElemAttr("data.elasticstack_elasticsearch_index_template.test", "ignore_missing_component_templates.*", fmt.Sprintf("%s-logs@custom", templateName)),
resource.TestCheckResourceAttr("data.elasticstack_elasticsearch_index_template.test", "priority", "100"),
),
},
Expand All @@ -40,10 +42,13 @@ resource "elasticstack_elasticsearch_index_template" "test" {

priority = 100
index_patterns = ["tf-acc-%s-*"]

composed_of = ["%s-logs@custom"]
ignore_missing_component_templates = ["%s-logs@custom"]
}

data "elasticstack_elasticsearch_index_template" "test" {
name = elasticstack_elasticsearch_index_template.test.name
}
`, templateName, templateName)
`, templateName, templateName, templateName, templateName)
}
14 changes: 12 additions & 2 deletions internal/elasticsearch/index/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestAccResourceIndexTemplate(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test", "name", templateName),
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_index_template.test", "index_patterns.*", fmt.Sprintf("%s-logs-*", templateName)),
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_index_template.test", "composed_of.*", fmt.Sprintf("%s-logs@custom", templateName)),
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_index_template.test", "ignore_missing_component_templates.*", fmt.Sprintf("%s-logs@custom", templateName)),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test", "priority", "42"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test", "template.0.alias.#", "1"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test2", "name", fmt.Sprintf("%s-stream", templateName)),
Expand All @@ -36,6 +38,8 @@ func TestAccResourceIndexTemplate(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test", "name", templateName),
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_index_template.test", "index_patterns.*", fmt.Sprintf("%s-logs-*", templateName)),
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_index_template.test", "composed_of.*", fmt.Sprintf("%s-logs-updated@custom", templateName)),
resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_index_template.test", "ignore_missing_component_templates.*", fmt.Sprintf("%s-logs-updated@custom", templateName)),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test", "template.0.alias.#", "2"),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test2", "name", fmt.Sprintf("%s-stream", templateName)),
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_template.test2", "data_stream.0.hidden", "false"),
Expand All @@ -57,6 +61,9 @@ resource "elasticstack_elasticsearch_index_template" "test" {
priority = 42
index_patterns = ["%s-logs-*"]

composed_of = ["%s-logs@custom"]
ignore_missing_component_templates = ["%s-logs@custom"]

template {
alias {
name = "my_template_test"
Expand All @@ -76,7 +83,7 @@ resource "elasticstack_elasticsearch_index_template" "test2" {
hidden = true
}
}
`, name, name, name)
`, name, name, name, name, name)
}

func testAccResourceIndexTemplateUpdate(name string) string {
Expand All @@ -90,6 +97,9 @@ resource "elasticstack_elasticsearch_index_template" "test" {

index_patterns = ["%s-logs-*"]

composed_of = ["%s-logs-updated@custom"]
ignore_missing_component_templates = ["%s-logs-updated@custom"]

template {
alias {
name = "my_template_test"
Expand All @@ -114,7 +124,7 @@ resource "elasticstack_elasticsearch_index_template" "test2" {

template {}
}
`, name, name, name)
`, name, name, name, name, name)
}

func checkResourceIndexTemplateDestroy(s *terraform.State) error {
Expand Down
21 changes: 11 additions & 10 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,17 @@ type Application struct {
}

type IndexTemplate struct {
Name string `json:"-"`
Create bool `json:"-"`
Timeout string `json:"-"`
ComposedOf []string `json:"composed_of"`
DataStream *DataStreamSettings `json:"data_stream,omitempty"`
IndexPatterns []string `json:"index_patterns"`
Meta map[string]interface{} `json:"_meta,omitempty"`
Priority *int `json:"priority,omitempty"`
Template *Template `json:"template,omitempty"`
Version *int `json:"version,omitempty"`
Name string `json:"-"`
Create bool `json:"-"`
Timeout string `json:"-"`
ComposedOf []string `json:"composed_of"`
IgnoreMissingComponentTemplates []string `json:"ignore_missing_component_templates"`
DataStream *DataStreamSettings `json:"data_stream,omitempty"`
IndexPatterns []string `json:"index_patterns"`
Meta map[string]interface{} `json:"_meta,omitempty"`
Priority *int `json:"priority,omitempty"`
Template *Template `json:"template,omitempty"`
Version *int `json:"version,omitempty"`
}

type DataStreamSettings struct {
Expand Down
Loading