-
Notifications
You must be signed in to change notification settings - Fork 123
Bump provider support to ES version 8.x
#72
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c166743
Switch to ES 8.0.0 in CI
olksdr 4e694f6
Use supported cluster settings
olksdr 31599cf
Fix index template: make sure it works with 8.x and 7.x ES versions
olksdr 86afe64
Add CHANGELOG record about the 8.x fix
olksdr ec5e137
Remove commented / unused code
olksdr 4e66998
Create template with "allow_custom_routing" on the first run if true
olksdr f5879c2
Update the index template test to include data_stream settings
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
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
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
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
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
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
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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package index | |
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "log" | ||
| "strings" | ||
|
|
||
| "github.com/elastic/terraform-provider-elasticstack/internal/clients" | ||
|
|
@@ -48,6 +49,11 @@ func ResourceTemplate() *schema.Resource { | |
| Default: false, | ||
| Optional: true, | ||
| }, | ||
| "allow_custom_routing": { | ||
| Description: "If `true`, the data stream supports custom routing. Defaults to `false`. Available only in *8.x*", | ||
| Type: schema.TypeBool, | ||
| Optional: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -195,10 +201,39 @@ func resourceIndexTemplatePut(ctx context.Context, d *schema.ResourceData, meta | |
| } | ||
| indexTemplate.ComposedOf = compsOf | ||
|
|
||
| if v, ok := d.GetOk("data_stream"); ok { | ||
| // only one definition of stream allowed | ||
| stream := v.([]interface{})[0].(map[string]interface{}) | ||
| indexTemplate.DataStream = stream | ||
| if d.HasChange("data_stream") { | ||
| old, new := d.GetChange("data_stream") | ||
| log.Printf("[TRACE] old data stream settings <%v> new settings <%v>", old, new) | ||
|
|
||
| // 8.x workaround | ||
| hasAllowCustomRouting := false | ||
| //for _, s := range []interface{}{old} { | ||
| if old != nil && len(old.([]interface{})) == 1 { | ||
| if old.([]interface{})[0] != nil { | ||
| setting := old.([]interface{})[0].(map[string]interface{}) | ||
| if _, ok := setting["allow_custom_routing"]; ok { | ||
| hasAllowCustomRouting = true | ||
| } | ||
| } | ||
| } | ||
| // } | ||
|
||
|
|
||
| if v, ok := d.GetOk("data_stream"); ok { | ||
| // only one definition of stream allowed | ||
| if v.([]interface{})[0] != nil { | ||
| stream := v.([]interface{})[0].(map[string]interface{}) | ||
| dSettings := &models.DataStreamSettings{} | ||
| if s, ok := stream["hidden"]; ok { | ||
| hidden := s.(bool) | ||
| dSettings.Hidden = &hidden | ||
| } | ||
| if s, ok := stream["allow_custom_routing"]; ok && hasAllowCustomRouting && s.(bool) { | ||
| allow := s.(bool) | ||
| dSettings.AllowCustomRouting = &allow | ||
| } | ||
| indexTemplate.DataStream = dSettings | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if v, ok := d.GetOk("index_patterns"); ok { | ||
|
|
@@ -298,9 +333,16 @@ func resourceIndexTemplateRead(ctx context.Context, d *schema.ResourceData, meta | |
| if err := d.Set("composed_of", tpl.IndexTemplate.ComposedOf); err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
| if tpl.IndexTemplate.DataStream != nil { | ||
| ds := make([]interface{}, 0) | ||
| ds = append(ds, tpl.IndexTemplate.DataStream) | ||
| if stream := tpl.IndexTemplate.DataStream; stream != nil { | ||
| ds := make([]interface{}, 1) | ||
| dSettings := make(map[string]interface{}) | ||
| if v := stream.Hidden; v != nil { | ||
| dSettings["hidden"] = *v | ||
| } | ||
| if v := stream.AllowCustomRouting; v != nil { | ||
| dSettings["allow_custom_routing"] = *v | ||
| } | ||
| ds[0] = dSettings | ||
| if err := d.Set("data_stream", ds); err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, done in ec5e137