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

Improve the provider initialization #322

Merged
merged 3 commits into from
Sep 27, 2017
Merged

Improve the provider initialization #322

merged 3 commits into from
Sep 27, 2017

Conversation

svanharmelen
Copy link

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, 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).

@svanharmelen
Copy link
Author

@tombuildsstuff would be great if you could review this PR so we can try to land it before the next release. Thx!

Sander van Harmelen added 3 commits September 26, 2017 22:41
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.
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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() {
Copy link
Contributor

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

Copy link
Contributor

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 :)

Copy link
Author

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 👍

@tombuildsstuff tombuildsstuff merged commit 524e770 into hashicorp:master Sep 27, 2017
tombuildsstuff added a commit that referenced this pull request Sep 27, 2017
@svanharmelen
Copy link
Author

Thanks @tombuildsstuff!

@svanharmelen svanharmelen deleted the f-registration branch October 6, 2017 07:53
@ghost
Copy link

ghost commented Apr 1, 2020

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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants