diff --git a/resources/cognito-userpool.go b/resources/cognito-userpool.go index 33fd6e82..fd528d73 100644 --- a/resources/cognito-userpool.go +++ b/resources/cognito-userpool.go @@ -99,13 +99,22 @@ type CognitoUserPool struct { func (r *CognitoUserPool) Remove(_ context.Context) error { if r.settings.GetBool("DisableDeletionProtection") { - _, err := r.svc.UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{ - UserPoolId: r.ID, - DeletionProtection: ptr.String("INACTIVE"), + userPool, err := r.svc.DescribeUserPool(&cognitoidentityprovider.DescribeUserPoolInput{ + UserPoolId: r.ID, }) if err != nil { return err } + + _, updateErr := r.svc.UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{ + UserPoolId: r.ID, + DeletionProtection: ptr.String("INACTIVE"), + UserAttributeUpdateSettings: userPool.UserPool.UserAttributeUpdateSettings, + AutoVerifiedAttributes: userPool.UserPool.AutoVerifiedAttributes, + }) + if updateErr != nil { + return updateErr + } } _, err := r.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{ diff --git a/resources/cognito-userpool_mock_test.go b/resources/cognito-userpool_mock_test.go index fc0bfa57..32244630 100644 --- a/resources/cognito-userpool_mock_test.go +++ b/resources/cognito-userpool_mock_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/gotidy/ptr" "github.com/stretchr/testify/assert" "github.com/aws/aws-sdk-go/aws" @@ -85,9 +86,24 @@ func Test_Mock_CognitoUserPool_Remove_DeletionProtection(t *testing.T) { mockSvc := mock_cognitoidentityprovideriface.NewMockCognitoIdentityProviderAPI(ctrl) + mockSvc.EXPECT().DescribeUserPool(&cognitoidentityprovider.DescribeUserPoolInput{ + UserPoolId: aws.String("test-pool-id"), + }).Return(&cognitoidentityprovider.DescribeUserPoolOutput{ + UserPool: &cognitoidentityprovider.UserPoolType{ + UserAttributeUpdateSettings: &cognitoidentityprovider.UserAttributeUpdateSettingsType{ + AttributesRequireVerificationBeforeUpdate: []*string{ptr.String("email")}, + }, + AutoVerifiedAttributes: []*string{ptr.String("email")}, + }, + }, nil) + mockSvc.EXPECT().UpdateUserPool(&cognitoidentityprovider.UpdateUserPoolInput{ UserPoolId: aws.String("test-pool-id"), DeletionProtection: aws.String("INACTIVE"), + UserAttributeUpdateSettings: &cognitoidentityprovider.UserAttributeUpdateSettingsType{ + AttributesRequireVerificationBeforeUpdate: []*string{ptr.String("email")}, + }, + AutoVerifiedAttributes: []*string{ptr.String("email")}, }).Return(&cognitoidentityprovider.UpdateUserPoolOutput{}, nil) mockSvc.EXPECT().DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{