11package index_test
22
33import (
4+ _ "embed"
45 "fmt"
56 "regexp"
67 "testing"
78
89 "github.com/elastic/terraform-provider-elasticstack/internal/acctest"
910 "github.com/elastic/terraform-provider-elasticstack/internal/clients"
11+ "github.com/hashicorp/terraform-plugin-testing/config"
1012 sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1113 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1214 "github.com/hashicorp/terraform-plugin-testing/terraform"
@@ -77,6 +79,9 @@ func TestAccResourceIndex(t *testing.T) {
7779 })
7880}
7981
82+ //go:embed testdata/TestAccResourceIndexFromSDK/index.tf
83+ var sdkCreateTestConfig string
84+
8085func TestAccResourceIndexFromSDK (t * testing.T ) {
8186 indexName := sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
8287
@@ -92,7 +97,10 @@ func TestAccResourceIndexFromSDK(t *testing.T) {
9297 VersionConstraint : "0.11.3" ,
9398 },
9499 },
95- Config : testAccResourceIndexSettingsCreate (indexName ),
100+ Config : sdkCreateTestConfig ,
101+ ConfigVariables : config.Variables {
102+ "index_name" : config .StringVariable (indexName ),
103+ },
96104 Check : resource .ComposeTestCheckFunc (
97105 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "name" , indexName ),
98106 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "number_of_shards" , "2" ),
@@ -132,7 +140,10 @@ func TestAccResourceIndexFromSDK(t *testing.T) {
132140 },
133141 {
134142 ProtoV6ProviderFactories : acctest .Providers ,
135- Config : testAccResourceIndexSettingsCreate (indexName ),
143+ ConfigDirectory : acctest .NamedTestCaseDirectory ("" ),
144+ ConfigVariables : config.Variables {
145+ "index_name" : config .StringVariable (indexName ),
146+ },
136147 Check : resource .ComposeTestCheckFunc (
137148 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "name" , indexName ),
138149 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "number_of_shards" , "2" ),
@@ -178,12 +189,15 @@ func TestAccResourceIndexSettings(t *testing.T) {
178189 indexName := sdkacctest .RandStringFromCharSet (22 , sdkacctest .CharSetAlphaNum )
179190
180191 resource .Test (t , resource.TestCase {
181- PreCheck : func () { acctest .PreCheck (t ) },
182- CheckDestroy : checkResourceIndexDestroy ,
183- ProtoV6ProviderFactories : acctest .Providers ,
192+ PreCheck : func () { acctest .PreCheck (t ) },
193+ CheckDestroy : checkResourceIndexDestroy ,
184194 Steps : []resource.TestStep {
185195 {
186- Config : testAccResourceIndexSettingsCreate (indexName ),
196+ ProtoV6ProviderFactories : acctest .Providers ,
197+ ConfigDirectory : acctest .NamedTestCaseDirectory ("create" ),
198+ ConfigVariables : config.Variables {
199+ "index_name" : config .StringVariable (indexName ),
200+ },
187201 Check : resource .ComposeTestCheckFunc (
188202 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "name" , indexName ),
189203 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "number_of_shards" , "2" ),
@@ -194,6 +208,7 @@ func TestAccResourceIndexSettings(t *testing.T) {
194208 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "sort_field.0" , "sort_key" ),
195209 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "sort_order.0" , "asc" ),
196210 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "mapping_coerce" , "true" ),
211+ resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "mapping_total_fields_limit" , "2000" ),
197212 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "auto_expand_replicas" , "0-5" ),
198213 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "search_idle_after" , "30s" ),
199214 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "refresh_interval" , "10s" ),
@@ -221,6 +236,17 @@ func TestAccResourceIndexSettings(t *testing.T) {
221236 resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "settings.0.setting.0.value" , "2" ),
222237 ),
223238 },
239+ {
240+ ProtoV6ProviderFactories : acctest .Providers ,
241+ ConfigDirectory : acctest .NamedTestCaseDirectory ("update" ),
242+ ConfigVariables : config.Variables {
243+ "index_name" : config .StringVariable (indexName ),
244+ },
245+ Check : resource .ComposeTestCheckFunc (
246+ resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "name" , indexName ),
247+ resource .TestCheckResourceAttr ("elasticstack_elasticsearch_index.test_settings" , "mapping_total_fields_limit" , "3000" ),
248+ ),
249+ },
224250 },
225251 })
226252}
@@ -348,84 +374,6 @@ resource "elasticstack_elasticsearch_index" "test" {
348374 ` , name )
349375}
350376
351- func testAccResourceIndexSettingsCreate (name string ) string {
352- return fmt .Sprintf (`
353- provider "elasticstack" {
354- elasticsearch {}
355- }
356-
357- resource "elasticstack_elasticsearch_index" "test_settings" {
358- name = "%s"
359-
360- mappings = jsonencode({
361- properties = {
362- field1 = { type = "text" }
363- sort_key = { type = "keyword" }
364- }
365- })
366-
367- number_of_shards = 2
368- number_of_routing_shards = 2
369- codec = "best_compression"
370- routing_partition_size = 1
371- shard_check_on_startup = "false"
372- sort_field = ["sort_key"]
373- sort_order = ["asc"]
374- mapping_coerce = true
375- auto_expand_replicas = "0-5"
376- search_idle_after = "30s"
377- refresh_interval = "10s"
378- max_result_window = 5000
379- max_inner_result_window = 2000
380- max_rescore_window = 1000
381- max_docvalue_fields_search = 1500
382- max_script_fields = 500
383- max_ngram_diff = 100
384- max_shingle_diff = 200
385- max_refresh_listeners = 10
386- analyze_max_token_count = 500000
387- highlight_max_analyzed_offset = 1000
388- max_terms_count = 10000
389- max_regex_length = 1000
390- query_default_field = ["field1"]
391- routing_allocation_enable = "primaries"
392- routing_rebalance_enable = "primaries"
393- gc_deletes = "30s"
394- unassigned_node_left_delayed_timeout = "5m"
395-
396- analysis_char_filter = jsonencode({
397- zero_width_spaces = {
398- type = "mapping"
399- mappings = ["\\u200C=>\\u0020"]
400- }
401- })
402- analysis_filter = jsonencode({
403- minimal_english_stemmer = {
404- type = "stemmer"
405- language = "minimal_english"
406- }
407- })
408- analysis_analyzer = jsonencode({
409- text_en = {
410- type = "custom"
411- tokenizer = "standard"
412- char_filter = "zero_width_spaces"
413- filter = ["lowercase", "minimal_english_stemmer"]
414- }
415- })
416-
417- settings {
418- setting {
419- name = "number_of_replicas"
420- value = "2"
421- }
422- }
423-
424- deletion_protection = false
425- }
426- ` , name )
427- }
428-
429377func testAccResourceIndexRemovingFieldCreate (name string ) string {
430378 return fmt .Sprintf (`
431379provider "elasticstack" {
0 commit comments