Skip to content

Commit 92b143a

Browse files
committed
Add importers for index lifecycle policy, template, pipeline.
1 parent 7f2e301 commit 92b143a

6 files changed

+119
-1
lines changed

Diff for: resource_elasticsearch_index_lifecycle_policy.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func resourceElasticsearchIndexLifecyclePolicy() *schema.Resource {
2828
DiffSuppressFunc: diffSuppressIndexLifecyclePolicy,
2929
},
3030
},
31+
Importer: &schema.ResourceImporter{
32+
State: schema.ImportStatePassthrough,
33+
},
3134
}
3235
}
3336

Diff for: resource_elasticsearch_index_lifecycle_policy_test.go

+38-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccElasticsearchIndexLifecyclePolicy(t *testing.T) {
3434
PreCheck: func() {
3535
testAccPreCheck(t)
3636
if !allowed {
37-
t.Skip("Destinations only supported on ES >= 6")
37+
t.Skip("Index lifecycles only supported on ES >= 6")
3838
}
3939
},
4040
Providers: testAccXPackProviders,
@@ -50,6 +50,43 @@ func TestAccElasticsearchIndexLifecyclePolicy(t *testing.T) {
5050
})
5151
}
5252

53+
func TestAccElasticsearchIndexLifecyclePolicy_importBasic(t *testing.T) {
54+
provider := Provider().(*schema.Provider)
55+
err := provider.Configure(&terraform.ResourceConfig{})
56+
if err != nil {
57+
t.Skipf("err: %s", err)
58+
}
59+
meta := provider.Meta()
60+
var allowed bool
61+
switch meta.(type) {
62+
case *elastic5.Client:
63+
allowed = false
64+
default:
65+
allowed = true
66+
}
67+
68+
resource.Test(t, resource.TestCase{
69+
PreCheck: func() {
70+
testAccPreCheck(t)
71+
if !allowed {
72+
t.Skip("Index lifecycles only supported on ES >= 6")
73+
}
74+
},
75+
Providers: testAccXPackProviders,
76+
CheckDestroy: testCheckElasticsearchIndexLifecyclePolicyDestroy,
77+
Steps: []resource.TestStep{
78+
{
79+
Config: testAccElasticsearchIndexLifecyclePolicy,
80+
},
81+
{
82+
ResourceName: "elasticsearch_index_lifecycle_policy.test",
83+
ImportState: true,
84+
ImportStateVerify: true,
85+
},
86+
},
87+
})
88+
}
89+
5390
func testCheckElasticsearchIndexLifecyclePolicyExists(name string) resource.TestCheckFunc {
5491
return func(s *terraform.State) error {
5592
rs, ok := s.RootModule().Resources[name]

Diff for: resource_elasticsearch_index_template.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func resourceElasticsearchIndexTemplate() *schema.Resource {
2828
DiffSuppressFunc: diffSuppressIndexTemplate,
2929
},
3030
},
31+
Importer: &schema.ResourceImporter{
32+
State: schema.ImportStatePassthrough,
33+
},
3134
}
3235
}
3336

Diff for: resource_elasticsearch_index_template_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ func TestAccElasticsearchIndexTemplate(t *testing.T) {
4747
})
4848
}
4949

50+
func TestAccElasticsearchIndexTemplate_importBasic(t *testing.T) {
51+
provider := Provider().(*schema.Provider)
52+
err := provider.Configure(&terraform.ResourceConfig{})
53+
if err != nil {
54+
t.Skipf("err: %s", err)
55+
}
56+
meta := provider.Meta()
57+
var config string
58+
switch meta.(type) {
59+
case *elastic7.Client:
60+
config = testAccElasticsearchIndexTemplateV7
61+
case *elastic6.Client:
62+
config = testAccElasticsearchIndexTemplateV6
63+
default:
64+
config = testAccElasticsearchIndexTemplateV5
65+
}
66+
67+
resource.Test(t, resource.TestCase{
68+
PreCheck: func() {
69+
testAccPreCheck(t)
70+
},
71+
Providers: testAccProviders,
72+
CheckDestroy: testCheckElasticsearchIndexTemplateDestroy,
73+
Steps: []resource.TestStep{
74+
{
75+
Config: config,
76+
},
77+
{
78+
ResourceName: "elasticsearch_index_template.test",
79+
ImportState: true,
80+
ImportStateVerify: true,
81+
},
82+
},
83+
})
84+
}
85+
5086
func testCheckElasticsearchIndexTemplateExists(name string) resource.TestCheckFunc {
5187
return func(s *terraform.State) error {
5288
rs, ok := s.RootModule().Resources[name]

Diff for: resource_elasticsearch_ingest_pipeline.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func resourceElasticsearchIngestPipeline() *schema.Resource {
2828
Required: true,
2929
},
3030
},
31+
Importer: &schema.ResourceImporter{
32+
State: schema.ImportStatePassthrough,
33+
},
3134
}
3235
}
3336

Diff for: resource_elasticsearch_ingest_pipeline_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ func TestAccElasticsearchIngestPipeline(t *testing.T) {
4747
})
4848
}
4949

50+
func TestAccElasticsearchIngestPipeline_importBasic(t *testing.T) {
51+
provider := Provider().(*schema.Provider)
52+
err := provider.Configure(&terraform.ResourceConfig{})
53+
if err != nil {
54+
t.Skipf("err: %s", err)
55+
}
56+
meta := provider.Meta()
57+
var config string
58+
switch meta.(type) {
59+
case *elastic7.Client:
60+
config = testAccElasticsearchIngestPipelineV7
61+
case *elastic6.Client:
62+
config = testAccElasticsearchIngestPipelineV6
63+
default:
64+
config = testAccElasticsearchIngestPipelineV5
65+
}
66+
67+
resource.Test(t, resource.TestCase{
68+
PreCheck: func() {
69+
testAccPreCheck(t)
70+
},
71+
Providers: testAccProviders,
72+
CheckDestroy: testCheckElasticsearchIngestPipelineDestroy,
73+
Steps: []resource.TestStep{
74+
{
75+
Config: config,
76+
},
77+
{
78+
ResourceName: "elasticsearch_ingest_pipeline.test",
79+
ImportState: true,
80+
ImportStateVerify: true,
81+
},
82+
},
83+
})
84+
}
85+
5086
func testCheckElasticsearchIngestPipelineExists(name string) resource.TestCheckFunc {
5187
return func(s *terraform.State) error {
5288
rs, ok := s.RootModule().Resources[name]

0 commit comments

Comments
 (0)