Prevent re-initialising terraform setups for the same providerconfig#220
Merged
xunholy merged 14 commits intocrossplane-contrib:mainfrom Sep 24, 2025
Merged
Conversation
…ing-tf-provider feat: prevent reconfiguring terraform setups for the same providerconfig
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Contributor
Author
Contributor
|
Awesome! would be nice to get this merged into main sooner than later. @timtatt I guess you still need to sign the commits so it passes the DCO check. |
fd355ac to
61665f1
Compare
Signed-off-by: Tim Tattersall <tim@tattsy.com>
Signed-off-by: Tim Tattersall <tim@tattsy.com>
61665f1 to
d783d77
Compare
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description of your changes
Observed behaviour where the /organizations/:organization_id endpoint has unusually high API usage. After some investigation, found that Terraform provider is being reconfigured for every reconciliation of every resource.
Given that the terraform providers exist at the ProviderConfig level, the terraform provider can be shared between resources. This change keeps a cache of tfSetups indexed by the ProviderConfig name. If the tfSetup is already available in the map, this will be used rather than creating a new terraform provider.
The tfSetups are scoped to the SetupFn and have a mutex lock to ensure only one ProviderConfig is being configured at a time. Note: if many ProviderConfigs are being used, there will be an initial delay setting up additional providers on startup due to mutex lock.
I have:
make reviewable testto ensure this PR is ready for review.How has this code been tested
This has been tested locally against my private account creating 4xRepository and 2xProviderConfig and expecting the provider to only be configured twice (once for each ProviderConfig)