Skip to content
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

Moving client creation to resource to allow for provider interpolation #119

Merged
merged 7 commits into from
Dec 15, 2020

Conversation

john-delivuk-rl
Copy link
Contributor

@john-delivuk-rl john-delivuk-rl commented Dec 8, 2020

While looking through I noticed several issues around being able to interpolate the provider. While this was an issue in previous version of terraform, it's been resolved. You can see in providers like MySQL, the providerConfigure only returns a configuration struct. I've implemented the same pattern to allow for proper resource dependencies. I think a few tests might still have an issue, but I'll work to remediate these today.

I think long term this code would benefit an interface around elastic search and a class factory to simply that logic, I tried to leave as much of the existing code alone as possible, as this is a large change already.

UPDATE: Running this locally and everything is running great. It's so nice to not use work arounds :)

@john-delivuk-rl john-delivuk-rl changed the title Moving client creation to allow for provider interpolation Moving client creation to resource to allow for provider interpolation Dec 8, 2020
@phillbaker
Copy link
Owner

Thanks for doing this! I'm curious why this isn't building on travis.

@john-delivuk-rl
Copy link
Contributor Author

I was curious about that too. I wasn't sure if there was something manual. Let me take a peak.

@john-delivuk-rl
Copy link
Contributor Author

.... I'm assuming you just did something xD

@john-delivuk-rl
Copy link
Contributor Author

Looks like Travis has disabled OSS builds. If you can trigger a rebuild when you have a second. This should be close..

@john-delivuk-rl
Copy link
Contributor Author

@phillbaker Happy to donate some money for additional credits. Right now the lowest price point for me to give credits is $70, and I'm more in the $10 - $20 contribution range :)

Would love to see this get merged and consume it.

@phillbaker
Copy link
Owner

I'm in the process of moving this repo to github actions. For the time being, if you'd like to run the tests locally, that'd be the quickest way to iterate on this PR.

@john-delivuk-rl
Copy link
Contributor Author

Will do.

@john-delivuk-rl
Copy link
Contributor Author

Tests are passing locally. Let me know if I can do anything further.

<no state>
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypeApply
2020/12/11 01:43:30 [WARN] Provider "elasticsearch" produced an invalid plan for elasticsearch_xpack_watch.test_watch, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .body: planned value cty.StringVal("{\"actions\":{\"test_log\":{\"logging\":{\"level\":\"info\",\"text\":\"executed at {{ctx.execution_time}}\"}}},\"condition\":{\"always\":{}},\"input\":{\"simple\":{\"payload\":{\"send\":\"yes\"}}},\"trigger\":{\"schedule\":{\"hourly\":{\"minute\":[0,5]}}}}") does not match config value cty.StringVal("{\n  \"input\": {\n    \"simple\": {\n      \"payload\": {\n        \"send\": \"yes\"\n      }\n    }\n  },\n  \"condition\": {\n    \"always\": {}\n  },\n  \"trigger\": {\n    \"schedule\": {\n      \"hourly\": {\n        \"minute\": [0, 5]\n      }\n    }\n  },\n  \"actions\": {\n    \"test_log\": {\n\t    \"logging\": {\n\t    \t\"level\": \"info\",\n\t      \"text\": \"executed at {{ctx.execution_time}}\"\n\t    }\n\t  }\n  }\n}\n")
2020/12/11 01:43:30 [INFO] Pinging url to determine version http://elastic:[email protected]:9210
2020/12/11 01:43:30 [INFO] Object ID: my_watch
2020/12/11 01:43:30 [WARN] Provider "elasticsearch" produced an unexpected new value for elasticsearch_xpack_watch.test_watch, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .body: was cty.StringVal("{\"actions\":{\"test_log\":{\"logging\":{\"level\":\"info\",\"text\":\"executed at {{ctx.execution_time}}\"}}},\"condition\":{\"always\":{}},\"input\":{\"simple\":{\"payload\":{\"send\":\"yes\"}}},\"trigger\":{\"schedule\":{\"hourly\":{\"minute\":[0,5]}}}}"), but now cty.StringVal("{\"trigger\":{\"schedule\":{\"hourly\":{\"minute\":[0,5]}}},\"input\":{\"simple\":{\"payload\":{\"send\":\"yes\"}}},\"condition\":{\"always\":{}},\"actions\":{\"test_log\":{\"logging\":{\"level\":\"info\",\"text\":\"executed at {{ctx.execution_time}}\"}}}}")
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypePlan
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/11 01:43:30 [INFO] Pinging url to determine version http://elastic:[email protected]:9210
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypePlan
2020/12/11 01:43:30 [WARN] Test: Executing destroy step
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypeValidate
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/11 01:43:30 [INFO] Pinging url to determine version http://elastic:[email protected]:9210
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypePlanDestroy
2020/12/11 01:43:30 [WARN] Test: Step plan: DIFF:

DESTROY: elasticsearch_xpack_watch.test_watch
  body:     "{\"trigger\":{\"schedule\":{\"hourly\":{\"minute\":[0,5]}}},\"input\":{\"simple\":{\"payload\":{\"send\":\"yes\"}}},\"condition\":{\"always\":{}},\"actions\":{\"test_log\":{\"logging\":{\"level\":\"info\",\"text\":\"executed at {{ctx.execution_time}}\"}}}}" => ""
  id:       "my_watch" => ""
  watch_id: "my_watch" => ""



STATE:

elasticsearch_xpack_watch.test_watch:
  ID = my_watch
  provider = provider.elasticsearch
  body = {"trigger":{"schedule":{"hourly":{"minute":[0,5]}}},"input":{"simple":{"payload":{"send":"yes"}}},"condition":{"always":{}},"actions":{"test_log":{"logging":{"level":"info","text":"executed at {{ctx.execution_time}}"}}}}
  watch_id = my_watch
2020/12/11 01:43:30 [INFO] terraform: building graph: GraphTypeApply
2020/12/11 01:43:30 DestroyEdgeTransformer: pruning unused resource node elasticsearch_xpack_watch.test_watch (prepare state)
2020/12/11 01:43:30 [INFO] Pinging url to determine version http://elastic:[email protected]:9210
2020/12/11 01:43:31 [INFO] terraform: building graph: GraphTypePlanDestroy
2020/12/11 01:43:31 [INFO] terraform: building graph: GraphTypeRefresh
2020/12/11 01:43:31 [INFO] terraform: building graph: GraphTypePlanDestroy
--- PASS: TestAccElasticsearchWatch (0.28s)
PASS
coverage: 55.4% of statements
ok  	github.com/phillbaker/terraform-provider-elasticsearch/es	20.030s	coverage: 55.4% of statements

@john-delivuk-rl
Copy link
Contributor Author

Saw another that in PR 120, the contributor setup travis in his own account. So I followed suit
https://travis-ci.com/github/john-delivuk-rl/terraform-provider-elasticsearch/builds/208632650

Copy link
Owner

@phillbaker phillbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the work on this, much appreciated!

if err != nil {
return err
}
if client, ok := esClient.(*elastic7.Client); ok {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should come back and use a switch/case here

@@ -8,6 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"

// "github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I should clean this up

return elastic7PutRoleMapping(client, name, body)
}
if client, ok := m.(*elastic6.Client); ok {
if client, ok := esClient.(*elastic6.Client); ok {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I should come back and use a switch/case in this file

if err != nil {
return err
}
if client, ok := esClient.(*elastic7.Client); ok {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More eventual clean up for switch/case

@phillbaker phillbaker merged commit 5302ba1 into phillbaker:master Dec 15, 2020
phillbaker added a commit to Wiston999/terraform-provider-elasticsearch that referenced this pull request Dec 15, 2020
* origin/master:
  Moving client creation to resource to allow for provider interpolation (phillbaker#119)
@john-delivuk-rl
Copy link
Contributor Author

Thanks for accepting this. Any idea on timeline for cutting another revision?

@john-delivuk-rl john-delivuk-rl deleted the provider-interpolation branch December 15, 2020 21:23
@phillbaker
Copy link
Owner

@john-delivuk-rl sorry for the slow response, it's released in https://registry.terraform.io/providers/phillbaker/elasticsearch/1.5.1-beta1, should be a full 1.5.1 in the next couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants