Skip to content

Commit 7b976cd

Browse files
committed
[composable index template] Fix diff on data_streams
Add covering test for this behavior
1 parent 22b7598 commit 7b976cd

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

es/resource_elasticsearch_composable_index_template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func resourceElasticsearchComposableIndexTemplateRead(d *schema.ResourceData, me
9595

9696
func elastic7GetIndexTemplate(client *elastic7.Client, id string) (string, error) {
9797
res, err := client.IndexGetIndexTemplate(id).Do(context.TODO())
98+
log.Printf("[INFO] Index template %+v %+v", res, err)
9899
if err != nil {
99100
return "", err
100101
}

es/resource_elasticsearch_composable_index_template_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func testCheckElasticsearchComposableIndexTemplateDestroy(s *terraform.State) er
141141

142142
switch client := esClient.(type) {
143143
case *elastic7.Client:
144-
_, err = client.IndexGetTemplate(rs.Primary.ID).Do(context.TODO())
144+
_, err = client.IndexGetIndexTemplate(rs.Primary.ID).Do(context.TODO())
145145
default:
146146
err = errors.New("/_index_template endpoint only supported on ES >= 7.8")
147147
}
@@ -165,7 +165,7 @@ resource "elasticsearch_composable_index_template" "test" {
165165
"template": {
166166
"settings": {
167167
"index": {
168-
"number_of_shards": 1
168+
"number_of_shards": "1"
169169
}
170170
},
171171
"mappings": {
@@ -184,7 +184,8 @@ resource "elasticsearch_composable_index_template" "test" {
184184
}
185185
},
186186
"priority": 200,
187-
"version": 3
187+
"version": 3,
188+
"data_stream": {}
188189
}
189190
EOF
190191
}

es/util.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ For legacy index templates (ES < 7.8) or /_template endpoint on ES >= 7.8 see no
141141
*/
142142
func normalizeComposableIndexTemplate(tpl map[string]interface{}) {
143143
delete(tpl, "version")
144+
145+
// data_stream accepts only the attribute "hidden", but can return additional attributes, so
146+
// remove them
147+
if dataStream, ok := tpl["data_stream"].(map[string]interface{}); ok {
148+
for k := range dataStream {
149+
if k != "hidden" {
150+
delete(dataStream, k)
151+
}
152+
}
153+
}
154+
144155
if innerTpl, ok := tpl["template"]; ok {
145156
if innerTplMap, ok := innerTpl.(map[string]interface{}); ok {
146157
if settings, ok := innerTplMap["settings"]; ok {

0 commit comments

Comments
 (0)