-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Improve the provider initialization #322
Conversation
@tombuildsstuff would be great if you could review this PR so we can try to land it before the next release. Thx! |
The `registerAzureResourceProvidersWithSubscription` function is being called exactly once while executing the `providerConfigure` func. In turn the `providerConfigure` func is also called exactly once while executing a Terraform command (e.g. plan, apply). So when executing TF commands from the commandline there is absolutely no added value for using a `sync.Once` as the registration call is only being executed once anyway. If on the other hand you use the TF packages in a long running microservice process (like we do), having this `sync.Once` actually causes issues when using multiple different (and regularly changing) provider credentials (as only the first used credentials will register the providers). So since it adds nothing, but does cause issues in specific setups, I refactored the provider to not use the `sync.Once` anymore.
Nice if you make multiple validation or plan calls in a row from a microservice, before actually making the apply call. With this option we can skip this expensive HTTP call as we already know the credentials are valid.
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.
Hey @svanharmelen
Thanks for this PR - apologies for the delay in reviewing this!
I've taken a look through and I'm going to run the acceptance tests against this branch to confirm this won't affect those running in parallel - but this otherwise LGTM :)
Thanks!
var err error | ||
providerRegistrationOnce.Do(func() { |
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'm not 100% sure of the original need for this - I'm assuming it's needed for the acceptance tests (which run in parallel) - to verify this I'll run the acceptance tests against this branch shortly to confirm
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.
Acceptance tests passed - so looks like we're good here :)
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.
Cool, good the hear that! And thanks for the review 👍
Thanks @tombuildsstuff! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
The
registerAzureResourceProvidersWithSubscription
function is being called exactly once while executing theproviderConfigure
func.In turn the
providerConfigure
func is also called exactly once while executing a Terraform command (e.g. plan, apply).So when executing TF commands from the commandline there is absolutely no added value for using a
sync.Once
as the registration call is only being executed once anyway.If on the other hand you use the TF packages in a long running microservice process (like we do), having this
sync.Once
actually causes issues when using multiple different (and regularly changing) provider credentials (as only the first used credentials will register the providers).So since it adds nothing, but does cause issues in specific setups, we refactored the provider to not use the
sync.Once
anymore.Additionally we added an option to skip the credential validation call. This is nice if you make multiple validation or plan calls in a row from a microservice so you can skip the expensive HTTP call (as you already know the credentials are valid).