fix: add pre-delete hook for cleanrooms membership to remove analysis templates - #3001
Open
cgeiaws wants to merge 1 commit into
Open
fix: add pre-delete hook for cleanrooms membership to remove analysis templates#3001cgeiaws wants to merge 1 commit into
cgeiaws wants to merge 1 commit into
Conversation
… templates The generic resource framework now supports an optional PreDeleteFunc hook that runs before Cloud Control API DeleteResource is called. This allows resource-type-specific cleanup of child resources that would otherwise cause 409 Conflict errors. For awscc_cleanrooms_membership, the hook lists all analysis templates via Cloud Control API ListResources, filters by membership ID, and deletes matching templates before the membership deletion proceeds. No new SDK dependencies - uses only the existing Cloud Control API client. Framework changes: - Added PreDeleteFunc type and preDeleteFunc field to genericResource - Added WithPreDeleteFunc() builder method on ResourceOptions - Modified Delete() handler to invoke the hook before DeleteResource Clean Rooms changes: - New membership_resource_hooks.go with preDeleteMembership() - Wired into membership resource options in generated file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Note
Closes #3000
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the library.
Changes to Security Controls
No changes to security controls. The pre-delete hook uses the same Cloud Control API client and credentials already available to the provider. No new SDK dependencies or IAM permissions are introduced. The hook calls Cloud Control API
ListResourcesandDeleteResourceforAWS::CleanRooms::AnalysisTemplate, which require the same permissions the user would need to manage these resources directly.Description
This PR addresses two related 409 Conflict errors in Clean Rooms resources caused by the generic CRUD framework's lack of resource-type-specific lifecycle hooks.
Bug 1:
awscc_cleanrooms_membershipdeletion fails when analysis templates exist. The Cloud Control API returns 409 because the CleanRooms service requires all child analysis templates to be removed first.Bug 2:
awscc_cleanrooms_configured_table_associationcreation fails withAlreadyExists. The Cloud Control API returns 409 when a configured table association for the same configured table already exists in the collaboration/membership (e.g., from a previous failed apply, out-of-band creation, or incompleteRequiresReplacecycle).Both bugs share the same root cause: the generic CRUD framework has no mechanism for resource-type-specific pre-delete or pre-create cleanup.
This PR adds a
PreDeleteFunchook to the generic resource framework and implements it for the Clean Rooms membership resource using only the existing Cloud Control API client — no new SDK dependencies. The same pattern can be extended with aPreCreateFuncorAlreadyExistsHandlerto address the configured table association creation issue.Framework changes (
internal/generic/resource.go)PreDeleteFunctype:func(ctx context.Context, provider Provider, id string) errorpreDeleteFuncfield togenericResourcestructWithPreDeleteFunc()builder method onResourceOptionsDelete()handler to call the hook beforeDeleteResourceif one is registeredClean Rooms membership hook (
internal/aws/cleanrooms/)membership_resource_hooks.go:preDeleteMembership()uses Cloud Control APIListResourcesforAWS::CleanRooms::AnalysisTemplate, filters results by membership ID prefix (identifiers areMembershipId|AnalysisTemplateId), and deletes matching templates via Cloud Control APIDeleteResourceopts.WithPreDeleteFunc(preDeleteMembership)in the generated resource fileDesign decisions
cleanrooms) is added, keeping the provider's generic architecture intact.force_destroyflag. Without it the delete simply fails — there's no valid use case for keeping orphaned analysis templates on a membership being destroyed.PreDeleteFuncthe same way.Testing
go build ./internal/...passes with no errorsinternal/generic/tests pass