-
Notifications
You must be signed in to change notification settings - Fork 105
Add component template resource #39
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
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
💚 CLA has been signed |
Hey @xunleii! Thanks for your contribution!
Could you, please, also provide the error you get? It would be great if you could open an issue with error and possibly traces, your TF version, the resource definition you're using to test this and system you're running this on. |
Hi @olksdr, thanks for your response (and thanks to the team for this provider). |
Hey @xunleii ,
I would prefer to use existing function, which is already used in the It would be better to keep this PR simpler and just introduce the new resource, with tests and docs and move any refactoring into separate PR. With refactoring it would be great to move many of free standing functions into the models methods. |
bfc4ef2
to
0beb7d4
Compare
Hi @olksdr, I rebased my branch on Thanks for your review ! |
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.
Looks nice!
I've added few comments about documentation generation, and the placement of the new resource.
@@ -0,0 +1,101 @@ | |||
--- |
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.
All the documentation in the docs/
folder is generated and should not be changed manually. See how it's done for template
resource:
terraform-provider-elasticstack/templates/resources/elasticsearch_index_template.md.tmpl
Lines 1 to 12 in 0beb7d4
--- | |
subcategory: "Index" | |
layout: "" | |
page_title: "Elasticstack: elasticstack_elasticsearch_index_template Resource" | |
description: |- | |
Creates or updates an index template. | |
--- | |
# Resource: elasticstack_elasticsearch_index_template | |
Creates or updates an index template. Index templates define settings, mappings, and aliases that can be applied automatically to new indices. See, https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-template.html | |
you could copy this template and change the specific parts in names and the paths to the examples and run make gen
to generate the required files, which you then can add into this PR as well.
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.
I used make docs-generate
to generate this file, but without adding the template file. I'll add it and regenete it the new documentation just after
@@ -0,0 +1,290 @@ | |||
package cluster |
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.
Could you, please, move this file into internal/elasticsearch/index/
folder (index
module), where the template
resource is located, just to keep them all together?
|
||
func ResourceComponentTemplate() *schema.Resource { | ||
// NOTE: component_template and index_template uses the same schema | ||
componentTemplateSchema := map[string]*schema.Schema{ |
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.
Please, also add the ID as Computed
value:
componentTemplateSchema := map[string]*schema.Schema{ | |
componentTemplateSchema := map[string]*schema.Schema{ | |
"id": { | |
Description: "Internal identifier of the resource", | |
Type: schema.TypeString, | |
Computed: true, | |
}, |
ok to test |
And one more thing:
|
Hi @olksdr, thanks for your review. I made all changes that you request me and put them inside two |
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.
Thanks for addressing my review comments.
Only one small thing left to do, see my 2 proposed suggestion, to handle the situation when the resource was deleted outside of the TF. Those 2 pieces of. code also need to be added in, and we are good to merge this new resource.
And thanks again for working on this!
Hi, I applied your suggestion and resolved the conflict on CHANGELOG. Thanks |
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.
lgtm
jenkins test this |
This PR adds new
component_template
resource to manage components template through TF resources.This is a "naive" implementation of this resource, mainly based on the
index_template
one (many part are copy/paste).Of course, if needed, I can spend more time to see how can I simplify by sharing code between
index_template
andcomponent_template
, but could decrease the readability.NOTE: this PR is "in conflict" with the https://github.com./elastic/terraform-provider-elasticstack/pull/38/files on how we flatten struct; I use a method directly on models and @olksdr uses a function that take the object as parameter. Because its PRs has been already reviewed, I can adapt my code for its PR to avoid conflict (keeping its work or using method on models, whichever you and @olksdr prefer).
NOTE²: https://github.com./elastic/terraform-provider-elasticstack/blob/main/internal/elasticsearch/index/template.go#L220 will panic if no
aliases
are defined onindex_template
. In order to avoid any conflict with https://github.com./elastic/terraform-provider-elasticstack/pull/38/files, I didn't made any changes to fix that. But if my PR is be based on the later one, I will fix it.NOTE³: My changes need more tests, so I'll add them tomorrow