Skip to content

Commit

Permalink
Merge pull request #9684 from terraform-providers/rfd-retry-cognito
Browse files Browse the repository at this point in the history
Final retries and deleting extraneous retry blocks from cognito resources
  • Loading branch information
ryndaniels authored Aug 12, 2019
2 parents cc3dba0 + c138fe7 commit 0ee7bc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
19 changes: 7 additions & 12 deletions aws/resource_aws_cognito_identity_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/cognitoidentity"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -245,15 +243,12 @@ func resourceAwsCognitoIdentityPoolDelete(d *schema.ResourceData, meta interface
conn := meta.(*AWSClient).cognitoconn
log.Printf("[DEBUG] Deleting Cognito Identity Pool: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteIdentityPool(&cognitoidentity.DeleteIdentityPoolInput{
IdentityPoolId: aws.String(d.Id()),
})

if err == nil {
return nil
}

return resource.NonRetryableError(err)
_, err := conn.DeleteIdentityPool(&cognitoidentity.DeleteIdentityPoolInput{
IdentityPoolId: aws.String(d.Id()),
})

if err != nil {
return fmt.Errorf("Error deleting Cognito identity pool: %s", err)
}
return nil
}
22 changes: 9 additions & 13 deletions aws/resource_aws_cognito_identity_pool_roles_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package aws
import (
"fmt"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/cognitoidentity"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)
Expand Down Expand Up @@ -222,19 +220,17 @@ func resourceAwsCognitoIdentityPoolRolesAttachmentDelete(d *schema.ResourceData,
conn := meta.(*AWSClient).cognitoconn
log.Printf("[DEBUG] Deleting Cognito Identity Pool Roles Association: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.SetIdentityPoolRoles(&cognitoidentity.SetIdentityPoolRolesInput{
IdentityPoolId: aws.String(d.Get("identity_pool_id").(string)),
Roles: expandCognitoIdentityPoolRoles(make(map[string]interface{})),
RoleMappings: expandCognitoIdentityPoolRoleMappingsAttachment([]interface{}{}),
})
_, err := conn.SetIdentityPoolRoles(&cognitoidentity.SetIdentityPoolRolesInput{
IdentityPoolId: aws.String(d.Get("identity_pool_id").(string)),
Roles: expandCognitoIdentityPoolRoles(make(map[string]interface{})),
RoleMappings: expandCognitoIdentityPoolRoleMappingsAttachment([]interface{}{}),
})

if err == nil {
return nil
}
if err != nil {
return fmt.Errorf("Error deleting Cognito identity pool roles association: %s", err)
}

return resource.NonRetryableError(err)
})
return nil
}

// Validating that each role_mapping ambiguous_role_resolution
Expand Down
6 changes: 6 additions & 0 deletions aws/resource_aws_cognito_user_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ func resourceAwsCognitoUserPoolCreate(d *schema.ResourceData, meta interface{})

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
resp, err = conn.CreateUserPool(params)
}
if err != nil {
return fmt.Errorf("Error creating Cognito User Pool: %s", err)
}
Expand Down Expand Up @@ -944,6 +947,9 @@ func resourceAwsCognitoUserPoolUpdate(d *schema.ResourceData, meta interface{})

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.UpdateUserPool(params)
}
if err != nil {
return fmt.Errorf("Error updating Cognito User pool: %s", err)
}
Expand Down

0 comments on commit 0ee7bc7

Please sign in to comment.