-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[WIP] Allow lazy AWSClient initialization. #20388
Conversation
AWSClient is currently statically initialized in `Config.Client()`, called by `providerConfigure`. This makes using the provider in a configuration-driven template dependant on having a valid set of aws credentials, even if the configuration provides for no aws resources to be managed. This commit, while keeping the same approach as a default, allows the user to configure this initialization to be delayed until (and if) necessary. In more detail, this commit/PR: - adds the provider configuration to `AWSClient.providerConfig` - moves the `AWSClient` initialization process to a new `AWSClient.Init() error` function. - adds a new provider parameter `lazy_init` (default `false`) - calls `AWSClient.Init` from `Config.Client()` only if `lazy_init` if `true` - adds a series of `ClientInit{CrudBase,CrudContext,Exists,MigrateState,CustomizeDiff,StateUpgrade}Func` wrapper functions used in each resource definition to integrate the current `Provider` arg function functionalities with a call to `AWSClient.Init()`.
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.
Welcome @dariko 👋
It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTING guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.
Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.
Thanks again, and welcome to the community! 😃
I suppose the from https://github.com/hashicorp/terraform-provider-aws/pull/20388/checks?check_run_id=3217790550 :
|
Pull request #21306 has significantly refactored the AWS Provider codebase. As a result, most PRs opened prior to the refactor now have merge conflicts that must be resolved before proceeding. Specifically, PR #21306 relocated the code for all AWS resources and data sources from a single We recognize that many pull requests have been open for some time without yet being addressed by our maintainers. Therefore, we want to make it clear that resolving these conflicts in no way affects the prioritization of a particular pull request. Once a pull request has been prioritized for review, the necessary changes will be made by a maintainer -- either directly or in collaboration with the pull request author. For a more complete description of this refactor, including examples of how old filepaths and function names correspond to their new counterparts: please refer to issue #20000. For a quick guide on how to amend your pull request to resolve the merge conflicts resulting from this refactor and bring it in line with our new code patterns: please refer to our Service Package Refactor Pull Request Guide. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
This PR tries to solve the problem reported in #20127
AWSClient is currently statically initialized in
Config.Client()
,called by
providerConfigure
.This makes using the provider in a configuration-driven template
dependant on having a valid set of aws credentials, even if the
configuration provides for no aws resources to be managed.
This PR, while keeping the same approach as a default, allows the
user to configure this initialization to be delayed until (and if)
necessary.
In more detail, this commit/PR:
AWSClient.providerConfig
AWSClient
initialization process to a newAWSClient.Init() error
function.lazy_init
(defaultfalse
)AWSClient.Init
fromConfig.Client()
only iflazy_init
if
true
ClientInit{CrudBase,CrudContext,Exists,MigrateState,CustomizeDiff,StateUpgrade}Func
wrapper functions
the current
Provider
arg function functionalities with a call toAWSClient.Init()
.I have no experience with go nor with terraform plugin development so I "might" have made some "unlucky" choises about
how to approach this problem; I opened this PR to see if this approach might be acceptable AND to gather some insight about how this problem could be approached.
I would have liked to be able to have a MUCH smaller impact in the codebase, but the need to handle the possible
AWSClient.Init()
errors (having no exception management in go) left me unable to find a more delicate solution.Community Note
Acceptance tests
I might be willing to run the whole acceptance test suite but I'd need to get at least a ballpark extimate of how much executing them all could cost: I don't think running them blindly would be wise.
As of now I have just run some random (small) subset of the suite, just to verify there were no error globally breaking functionalities; I just got returned errors which seems to be not linked to my changes but to the environment(my amazon account/target region) or timeouts.
Some of these tests took a "not-short" time to complete, making me weary about the cost of running the whole suite.
some more output here: https://gist.github.com/dariko/5d0a5467582735f5473321b4025f8ebb
I should also write tests for the new provider
lazy_init
parameter: I have not begun yet, I just run some local basic tests.Closes #20127