Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contrib/pkg/awstagdeprovision: Allow for OR filters
AWS docs for filters are a bit sparse, but [1] has: Combining search filters In general, multiple filters with the same key field (for example, tag:Name, search, Instance State) are automatically joined with OR. This is intentional, as the vast majority of filters would not be logical if they were joined with AND. For example, you would get zero results for a search on Instance State=running AND Instance State=stopped. In many cases, you can granulate the results by using complementary search terms on different key fields, where the AND rule is automatically applied instead. If you search for tag: Name:=All values and tag:Instance State=running, you get search results that contain both those criteria. To fine-tune your results, simply remove one filter in the string until the results fit your requirements. Unfortunately, there seems to be no way to represent OR filters in ec2's Filter structure [2]. With the approach I have here, resources that match multiple filters will be fetched multiple times, and may have parallel, racing delete attempts. But we should be robust in the face of racing delete attempt, and hopefully one of the deletes will go through before too long ;). It would be possible to adjust our locally-filtered types (which use filterObjects) to avoid this issue for those types. I may do that in follow-up work, but for now I'm treating all of our types the same way. [1]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Filtering.html#advancedsearch [2]: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#Filter
- Loading branch information