-
Notifications
You must be signed in to change notification settings - Fork 123
Add new resource to manage ingest pipelines #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d14bb8
Add resource to manage ingest pipelines
olksdr 4e3896d
Add record to CHANGELOG about new ingest_pipeline resource
olksdr 056369e
Merge branch 'main' into feat/ingest-pipelines
olksdr df981a6
Add test for ingest pipeline resource
olksdr e838393
Update internal/elasticsearch/ingest/pipeline_test.go
olksdr 0fa5ee0
Update internal/elasticsearch/ingest/pipeline_test.go
olksdr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,114 @@ | ||
| package ingest_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/elastic/terraform-provider-elasticstack/internal/acctest" | ||
| "github.com/elastic/terraform-provider-elasticstack/internal/clients" | ||
| sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
| ) | ||
|
|
||
| func TestAccResourceIngestPipeline(t *testing.T) { | ||
| pipelineName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum) | ||
|
|
||
| resource.UnitTest(t, resource.TestCase{ | ||
| PreCheck: func() { acctest.PreCheck(t) }, | ||
| CheckDestroy: checkResourceIngestPipelineDestroy, | ||
| ProviderFactories: acctest.Providers, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testAccResourceIngestPipelineCreate(pipelineName), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr("elasticstack_elasticsearch_ingest_pipeline.test_pipeline", "name", pipelineName), | ||
| resource.TestCheckResourceAttr("elasticstack_elasticsearch_ingest_pipeline.test_pipeline", "description", "Test Pipeline"), | ||
| resource.TestCheckResourceAttr("elasticstack_elasticsearch_ingest_pipeline.test_pipeline", "processors.#", "2"), | ||
| ), | ||
| }, | ||
| { | ||
| Config: testAccResourceIngestPipelineUpdate(pipelineName), | ||
| Check: resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr("elasticstack_elasticsearch_ingest_pipeline.test_pipeline", "name", pipelineName), | ||
| resource.TestCheckResourceAttr("elasticstack_elasticsearch_ingest_pipeline.test_pipeline", "description", "Test Pipeline"), | ||
| resource.TestCheckResourceAttr("elasticstack_elasticsearch_ingest_pipeline.test_pipeline", "processors.#", "1"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func testAccResourceIngestPipelineCreate(name string) string { | ||
| return fmt.Sprintf(` | ||
| provider "elasticstack" { | ||
| elasticsearch {} | ||
| } | ||
| resource "elasticstack_elasticsearch_ingest_pipeline" "test_pipeline" { | ||
| name = "%s" | ||
| description = "Test Pipeline" | ||
| processors = [ | ||
| jsonencode({ | ||
| set = { | ||
| description = "My set processor descirption" | ||
| field = "_meta" | ||
| value = "indexed" | ||
| } | ||
| }), | ||
| <<EOF | ||
| {"json": { | ||
| "field": "data", | ||
| "target_field": "parsed_data" | ||
| }} | ||
| EOF | ||
| , | ||
| ] | ||
| } | ||
| `, name) | ||
| } | ||
|
|
||
| func testAccResourceIngestPipelineUpdate(name string) string { | ||
| return fmt.Sprintf(` | ||
| provider "elasticstack" { | ||
| elasticsearch {} | ||
| } | ||
| resource "elasticstack_elasticsearch_ingest_pipeline" "test_pipeline" { | ||
| name = "%s" | ||
| description = "Test Pipeline" | ||
| processors = [ | ||
| jsonencode({ | ||
| set = { | ||
| description = "My set processor descirption" | ||
olksdr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| field = "_meta" | ||
| value = "indexed" | ||
| } | ||
| }) | ||
| ] | ||
| } | ||
| `, name) | ||
| } | ||
|
|
||
| func checkResourceIngestPipelineDestroy(s *terraform.State) error { | ||
| client := acctest.Provider.Meta().(*clients.ApiClient) | ||
|
|
||
| for _, rs := range s.RootModule().Resources { | ||
| if rs.Type != "elasticstack_elasticsearch_ingest_pipeline" { | ||
| continue | ||
| } | ||
| compId, _ := clients.CompositeIdFromStr(rs.Primary.ID) | ||
|
|
||
| res, err := client.GetESClient().Indices.Get([]string{compId.ResourceId}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if res.StatusCode != 404 { | ||
| return fmt.Errorf("Ingest pipeline (%s) still exists", compId.ResourceId) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.