6
6
7
7
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
8
8
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
9
+ "github.com/elastic/terraform-provider-elasticstack/internal/elasticsearch/index"
10
+ "github.com/elastic/terraform-provider-elasticstack/internal/versionutils"
9
11
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
10
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11
13
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
@@ -14,6 +16,7 @@ import (
14
16
func TestAccResourceIndexTemplate (t * testing.T ) {
15
17
// generate random template name
16
18
templateName := sdkacctest .RandStringFromCharSet (10 , sdkacctest .CharSetAlphaNum )
19
+ templateNameComponent := sdkacctest .RandStringFromCharSet (10 , sdkacctest .CharSetAlphaNum )
17
20
18
21
resource .Test (t , resource.TestCase {
19
22
PreCheck : func () { acctest .PreCheck (t ) },
@@ -25,8 +28,6 @@ func TestAccResourceIndexTemplate(t *testing.T) {
25
28
Check : resource .ComposeTestCheckFunc (
26
29
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test" , "name" , templateName ),
27
30
resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test" , "index_patterns.*" , fmt .Sprintf ("%s-logs-*" , templateName )),
28
- resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test" , "composed_of.*" , fmt .Sprintf ("%s-logs@custom" , templateName )),
29
- resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test" , "ignore_missing_component_templates.*" , fmt .Sprintf ("%s-logs@custom" , templateName )),
30
31
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test" , "priority" , "42" ),
31
32
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test" , "template.0.alias.#" , "1" ),
32
33
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test2" , "name" , fmt .Sprintf ("%s-stream" , templateName )),
@@ -38,13 +39,31 @@ func TestAccResourceIndexTemplate(t *testing.T) {
38
39
Check : resource .ComposeTestCheckFunc (
39
40
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test" , "name" , templateName ),
40
41
resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test" , "index_patterns.*" , fmt .Sprintf ("%s-logs-*" , templateName )),
41
- resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test" , "composed_of.*" , fmt .Sprintf ("%s-logs-updated@custom" , templateName )),
42
- resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test" , "ignore_missing_component_templates.*" , fmt .Sprintf ("%s-logs-updated@custom" , templateName )),
43
42
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test" , "template.0.alias.#" , "2" ),
44
43
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test2" , "name" , fmt .Sprintf ("%s-stream" , templateName )),
45
44
resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test2" , "data_stream.0.hidden" , "false" ),
46
45
),
47
46
},
47
+ {
48
+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (index .MinSupportedIgnoreMissingComponentTemplateVersion ),
49
+ Config : testAccResourceIndexTemplateCreateWithIgnoreComponent (templateNameComponent ),
50
+ Check : resource .ComposeTestCheckFunc (
51
+ resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test_component" , "name" , templateNameComponent ),
52
+ resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test_component" , "index_patterns.*" , fmt .Sprintf ("%s-logscomponent-*" , templateNameComponent )),
53
+ resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test_component" , "composed_of.*" , fmt .Sprintf ("%s-logscomponent@custom" , templateNameComponent )),
54
+ resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test_component" , "ignore_missing_component_templates.*" , fmt .Sprintf ("%s-logscomponent@custom" , templateNameComponent )),
55
+ ),
56
+ },
57
+ {
58
+ SkipFunc : versionutils .CheckIfVersionIsUnsupported (index .MinSupportedIgnoreMissingComponentTemplateVersion ),
59
+ Config : testAccResourceIndexTemplateUpdateWithIgnoreComponent (templateNameComponent ),
60
+ Check : resource .ComposeTestCheckFunc (
61
+ resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index_template.test_component" , "name" , templateNameComponent ),
62
+ resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test_component" , "index_patterns.*" , fmt .Sprintf ("%s-logscomponent-*" , templateNameComponent )),
63
+ resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test_component" , "composed_of.*" , fmt .Sprintf ("%s-logscomponent-updated@custom" , templateNameComponent )),
64
+ resource .TestCheckTypeSetElemAttr ("elasticstack_elasticsearch_index_template.test_component" , "ignore_missing_component_templates.*" , fmt .Sprintf ("%s-logscomponent-updated@custom" , templateNameComponent )),
65
+ ),
66
+ },
48
67
},
49
68
})
50
69
}
@@ -61,9 +80,6 @@ resource "elasticstack_elasticsearch_index_template" "test" {
61
80
priority = 42
62
81
index_patterns = ["%s-logs-*"]
63
82
64
- composed_of = ["%s-logs@custom"]
65
- ignore_missing_component_templates = ["%s-logs@custom"]
66
-
67
83
template {
68
84
alias {
69
85
name = "my_template_test"
@@ -83,7 +99,7 @@ resource "elasticstack_elasticsearch_index_template" "test2" {
83
99
hidden = true
84
100
}
85
101
}
86
- ` , name , name , name , name , name )
102
+ ` , name , name , name )
87
103
}
88
104
89
105
func testAccResourceIndexTemplateUpdate (name string ) string {
@@ -97,9 +113,6 @@ resource "elasticstack_elasticsearch_index_template" "test" {
97
113
98
114
index_patterns = ["%s-logs-*"]
99
115
100
- composed_of = ["%s-logs-updated@custom"]
101
- ignore_missing_component_templates = ["%s-logs-updated@custom"]
102
-
103
116
template {
104
117
alias {
105
118
name = "my_template_test"
@@ -124,7 +137,42 @@ resource "elasticstack_elasticsearch_index_template" "test2" {
124
137
125
138
template {}
126
139
}
127
- ` , name , name , name , name , name )
140
+ ` , name , name , name )
141
+ }
142
+
143
+ func testAccResourceIndexTemplateCreateWithIgnoreComponent (name string ) string {
144
+ return fmt .Sprintf (`
145
+ provider "elasticstack" {
146
+ elasticsearch {}
147
+ }
148
+
149
+ resource "elasticstack_elasticsearch_index_template" "test_component" {
150
+ name = "%s"
151
+ index_patterns = ["%s-logscomponent-*"]
152
+
153
+ composed_of = ["%s-logscomponent@custom"]
154
+ ignore_missing_component_templates = ["%s-logscomponent@custom"]
155
+ }
156
+ ` , name , name , name , name )
157
+ }
158
+
159
+ func testAccResourceIndexTemplateUpdateWithIgnoreComponent (name string ) string {
160
+ return fmt .Sprintf (`
161
+ provider "elasticstack" {
162
+ elasticsearch {}
163
+ }
164
+
165
+ resource "elasticstack_elasticsearch_index_template" "test_component" {
166
+ name = "%s"
167
+ index_patterns = ["%s-logscomponent-*"]
168
+
169
+ composed_of = ["%s-logscomponent-updated@custom"]
170
+ ignore_missing_component_templates = ["%s-logscomponent-updated@custom"]
171
+
172
+ template {
173
+ }
174
+ }
175
+ ` , name , name , name , name )
128
176
}
129
177
130
178
func checkResourceIndexTemplateDestroy (s * terraform.State ) error {
0 commit comments