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

[WIP] Early stages of some ideas to standardize/generate sweepers #13516

Closed
wants to merge 17 commits into from

Conversation

gdavison
Copy link
Contributor

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.

@ghost ghost added size/XL Managed by automation to categorize the size of a PR. service/cloudformation Issues and PRs that pertain to the cloudformation service. service/kafka Issues and PRs that pertain to the kafka service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels May 27, 2020
}

// generate
func listAllCloudFormationStackSetsPages(conn *cloudformation.CloudFormation, fn func(*cloudformation.ListStackSetsOutput, bool) bool) error {
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

@ghost ghost added the provider Pertains to the provider itself, rather than any interaction with AWS. label Jun 1, 2020
@gdavison gdavison force-pushed the f-common-resource-operations branch from a682c08 to 5101128 Compare June 1, 2020 20:52
break
}

input.NextToken = output.NextToken
Copy link
Contributor

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'.

Copy link
Contributor Author

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 :)

@ghost ghost added service/rds Issues and PRs that pertain to the rds service. size/XXL Managed by automation to categorize the size of a PR. and removed size/XL Managed by automation to categorize the size of a PR. labels Jun 8, 2020
@gdavison gdavison force-pushed the f-common-resource-operations branch from f63f342 to e5a798e Compare June 10, 2020 23:55

var sweeperErrs *multierror.Error

err = lister.ListAllStackSetsPages(conn, func(page *cloudformation.ListStackSetsOutput, lastPage bool) bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Committed too early 🤦

@zhelding
Copy link
Contributor

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 aws directory to a large number of separate directories in internal/service, each corresponding to a particular AWS service. This separation of code has also allowed for us to simplify the names of underlying functions -- while still avoiding namespace collisions.

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.

Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 16, 2023
@ewbankkit ewbankkit deleted the f-common-resource-operations branch February 9, 2024 14:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
provider Pertains to the provider itself, rather than any interaction with AWS. service/cloudformation Issues and PRs that pertain to the cloudformation service. service/kafka Issues and PRs that pertain to the kafka service. service/rds Issues and PRs that pertain to the rds service. size/XXL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants