Skip to content

Prevent re-initialising terraform setups for the same providerconfig#220

Merged
xunholy merged 14 commits intocrossplane-contrib:mainfrom
timtatt:fix/reconfiguring-tf-provider
Sep 24, 2025
Merged

Prevent re-initialising terraform setups for the same providerconfig#220
xunholy merged 14 commits intocrossplane-contrib:mainfrom
timtatt:fix/reconfiguring-tf-provider

Conversation

@timtatt
Copy link
Copy Markdown
Contributor

@timtatt timtatt commented Sep 4, 2025

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.

image

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:

  • [] Read and followed Crossplane's contribution process.
  • Run make reviewable test to 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)

AtzeDeVries and others added 3 commits September 10, 2025 19:47
…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>
@timtatt
Copy link
Copy Markdown
Contributor Author

timtatt commented Sep 15, 2025

After running this snapshot in our dev environment we saw a significant reduction in API usage

image

@fernandezcuesta
Copy link
Copy Markdown
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.

@timtatt timtatt force-pushed the fix/reconfiguring-tf-provider branch from fd355ac to 61665f1 Compare September 16, 2025 11:27
Signed-off-by: Tim Tattersall <tim@tattsy.com>
@timtatt timtatt force-pushed the fix/reconfiguring-tf-provider branch from 61665f1 to d783d77 Compare September 16, 2025 11:27
@timtatt timtatt marked this pull request as ready for review September 16, 2025 11:27
AtzeDeVries and others added 8 commits September 19, 2025 15:17
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Signed-off-by: Atze de Vries <atze.wiebe.de.vries@coop.no>
Copy link
Copy Markdown
Collaborator

@xunholy xunholy left a comment

Choose a reason for hiding this comment

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

LGTM

@xunholy xunholy merged commit 3a3c379 into crossplane-contrib:main Sep 24, 2025
6 checks passed
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.

4 participants