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

Faster refresh via batching #1497

Open
foyerunix opened this issue Jan 3, 2025 · 0 comments
Open

Faster refresh via batching #1497

foyerunix opened this issue Jan 3, 2025 · 0 comments
Labels
enhancement Enhancement

Comments

@foyerunix
Copy link

foyerunix commented Jan 3, 2025

Is your feature request related to a problem? Please describe.

Hello,

I'm currently working on implementing micro-segmentation using NSX-T with the Terraform provider. Given the size of our environment, I had to automate the rules creation process for the existing connections. This led me to already having thousands of rules, groups, and services while I still didn't put the majority of my VMs into NSX-T.

When running "terraform plan" and then "terraform plan -refresh=false", I can see that the great majority of the time is spent refreshing the state.

As I understand, this is because the provider is currently designed to make one request per policy, group, and service to refresh. Given that the vast majority of my policy, group, and service are defined in Terraform, I think it would be faster to simply list all of them at the start rather than making an individual request per resource.

Describe the solution you'd like

After having read this issue (hashicorp/terraform-plugin-sdk#7), I understand that request batching in Terraform is a complex problem.

Meanwhile, maybe we could implement the following strategy:

  • The users can opt-in to choose the resource types to refresh via batching; the behavior for resources without this option would remain unchanged.
  • In the planning phase, the first instance of the resource of a selected type we try to refresh acquires a lock (for its own type only).
  • We fetch all the instances of this type of resource using the listing API and put them in some in-memory cache.
  • Once the cache is filled, the lock is released, and the refreshed resource is then retrieved from the cache.

If this sounds like an acceptable solution to you, I can prepare a PR to implement this. Given that I'm unfamiliar with Terraform providers, any advice would be welcome.

Best Regards.

Describe alternatives you've considered

No response

Additional context

No response

@foyerunix foyerunix added the enhancement Enhancement label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement
Projects
None yet
Development

No branches or pull requests

1 participant