-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[WIP] Early stages of some ideas to standardize/generate sweepers #13516
Conversation
} | ||
|
||
// generate | ||
func listAllCloudFormationStackSetsPages(conn *cloudformation.CloudFormation, fn func(*cloudformation.ListStackSetsOutput, bool) bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're creating our own List*Pages()
from the List*()
function the AWS API provides. This can be easily generated, since it follows a standard pattern, and could be swapped out if/when the API adds a paged function.
@@ -13,6 +13,12 @@ import ( | |||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | |||
) | |||
|
|||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be moved to the service package
@@ -22,76 +21,64 @@ func init() { | |||
} | |||
|
|||
func testSweepCloudformationStackSetInstances(region string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an example of a two-level iteration for nested objects
@@ -24,46 +24,54 @@ func init() { | |||
}) | |||
} | |||
|
|||
func testSweepCloudformationStackSets(region string) error { | |||
// generate | |||
func sharedCloudFormationClientForRegion(region string) (*cloudformation.CloudFormation, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wrapping might be overkill, but it gives a standard naming pattern
return nil | ||
} | ||
// generate | ||
func serviceConnectionCloudFormation(client interface{}) *cloudformation.CloudFormation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wrapping might be overkill, but it gives a standard naming pattern
if err != nil { | ||
return fmt.Errorf("error deleting CloudFormation StackSet (%s): %s", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func listCloudFormationStackSets(conn *cloudformation.CloudFormation) ([]*cloudformation.StackSetSummary, error) { | ||
func deleteCloudFormationStackSet(conn *cloudformation.CloudFormation, name string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any thoughts around having the resource manipulation functions in a service-specific package (e.g internal/service/cloudformation/actions
)?
The implementation becomes
func DeleteStackSet(conn *cloudformation.CloudFormation, name string) error {...}
and the caller
err := actions.DeleteStackSet(conn, d.Id())
It may make code generation easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they would definitely belong there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should definitely be moved to something like that. We'll have to figure out where to move isAWSErr()
first, because otherwise we'll have a dependency loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#13036 should help with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I was about to create an issue for that
a682c08
to
5101128
Compare
break | ||
} | ||
|
||
input.NextToken = output.NextToken |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field isn't always named NextToken
, for example RDS Cluster Parameters use `Marker'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good to know. Thanks!
We'll probably need some kind of customization spec. Or punt and do it manually :)
…ions to `lister` package
Needed to add a paginator field name to the generator function, since not all services use `NextToken`. Removed the waiter for `aws_rds_cluster_parameter_group` deletion, since it always exited on the first call.
…ata and API resource
f63f342
to
e5a798e
Compare
|
||
var sweeperErrs *multierror.Error | ||
|
||
err = lister.ListAllStackSetsPages(conn, func(page *cloudformation.ListStackSetsOutput, lastPage bool) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed too early 🤦
Pull request #21306 has significantly refactored the AWS Provider codebase. As a result, most PRs opened prior to the refactor now have merge conflicts that must be resolved before proceeding. Specifically, PR #21306 relocated the code for all AWS resources and data sources from a single We recognize that many pull requests have been open for some time without yet being addressed by our maintainers. Therefore, we want to make it clear that resolving these conflicts in no way affects the prioritization of a particular pull request. Once a pull request has been prioritized for review, the necessary changes will be made by a maintainer -- either directly or in collaboration with the pull request author. For a more complete description of this refactor, including examples of how old filepaths and function names correspond to their new counterparts: please refer to issue #20000. For a quick guide on how to amend your pull request to resolve the merge conflicts resulting from this refactor and bring it in line with our new code patterns: please refer to our Service Package Refactor Pull Request Guide. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
This draft PR starts sketching out some ways to standardize utility functions so that e.g. sweepers can be generated using those standard operations.