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

Document how to write and use sweepers in contributor docs #17891

Open
melinath opened this issue Apr 17, 2024 · 6 comments
Open

Document how to write and use sweepers in contributor docs #17891

melinath opened this issue Apr 17, 2024 · 6 comments
Labels
documentation mmv1-generator Provider-wide changes to resource templates or other generator changes size/m technical-debt
Milestone

Comments

@melinath
Copy link
Collaborator

melinath commented Apr 17, 2024

What kind of contribution is this issue about?

Other (specify in details)

Details

We should document how to write and use sweepers. Currently we have https://github.com/hashicorp/terraform-provider-google/wiki/Developer-Best-Practices#sweepers but that's not accessible to users.

This may make sense to do as part of a broader effort to make sweepers more accessible to users, for example by making them configurable.

References

#16859
#17835
yaqs/6453048037068505088

@SarahFrench
Copy link
Member

Data point for this issue: GoogleCloudPlatform/magic-modules#11413 (comment)

@melinath
Copy link
Collaborator Author

@SarahFrench
Copy link
Member

This information in the old CONTRIBUTING.md for TPG will be useful for this issue:

Running provider tests often can lead to dangling test resources caused by test failures. Terraform has a capability to run Sweepers which can go through and delete resources. In TPG, sweepers mainly:

  1. List every resource in a project of a specific kind
  2. Iterate through the list and determine if a resource is sweepable
  3. If sweepable, delete the resource

Sweepers run by using the -sweep and -sweep-run TESTARGS flags:

TF_LOG=TRACE make testacc TEST=./google TESTARGS='-sweep=us-central1 -sweep-run=<sweeper-name-here>' > output.log

@SarahFrench
Copy link
Member

Some more information:

  • The sweeper name is the string used to register the sweeper in the provider, e.g. here the name is "ComputeDisk". This is the value used for -sweep-run=<sweeper-name-here> above
  • The -sweep flag determines which value is passed through as the region string argument to the sweeper function (see here)
  • The 'entrypoint' for sweepers is the sweeper package, and individual sweepers from other packages are registered there using sweeper.AddTestSweepers

@SarahFrench
Copy link
Member

Here's an example of where some docs about sweepers would be helpful: #19983 (comment)

@owenhuyn
Copy link

It looks like another PR #12334 would have been helpful to have sweepers documented since there was some engineering friction with the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation mmv1-generator Provider-wide changes to resource templates or other generator changes size/m technical-debt
Projects
None yet
Development

No branches or pull requests

3 participants