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

r/cognito_user_pool_client - add revocation support + retry on concurrent changes #20031

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions aws/resource_aws_cognito_user_pool_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ func resourceAwsCognitoUserPoolClient() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 1024),
validation.StringLenBetween(0, 1024),
validation.StringMatch(regexp.MustCompile(`[\p{L}\p{M}\p{S}\p{N}\p{P}]+`),
"must satisfy regular expression pattern: [\\p{L}\\p{M}\\p{S}\\p{N}\\p{P}]+`"),
),
},
"enable_token_revocation": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"explicit_auth_flows": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -311,6 +316,10 @@ func resourceAwsCognitoUserPoolClientCreate(d *schema.ResourceData, meta interfa
params.PreventUserExistenceErrors = aws.String(v.(string))
}

if v, ok := d.GetOk("enable_token_revocation"); ok {
params.EnableTokenRevocation = aws.Bool(v.(bool))
}

log.Printf("[DEBUG] Creating Cognito User Pool Client: %s", params)

resp, err := conn.CreateUserPoolClient(params)
Expand Down Expand Up @@ -363,6 +372,7 @@ func resourceAwsCognitoUserPoolClientRead(d *schema.ResourceData, meta interface
d.Set("logout_urls", flattenStringSet(userPoolClient.LogoutURLs))
d.Set("prevent_user_existence_errors", userPoolClient.PreventUserExistenceErrors)
d.Set("supported_identity_providers", flattenStringSet(userPoolClient.SupportedIdentityProviders))
d.Set("enable_token_revocation", userPoolClient.EnableTokenRevocation)

if err := d.Set("analytics_configuration", flattenAwsCognitoUserPoolClientAnalyticsConfig(userPoolClient.AnalyticsConfiguration)); err != nil {
return fmt.Errorf("error setting analytics_configuration: %w", err)
Expand All @@ -379,8 +389,9 @@ func resourceAwsCognitoUserPoolClientUpdate(d *schema.ResourceData, meta interfa
conn := meta.(*AWSClient).cognitoidpconn

params := &cognitoidentityprovider.UpdateUserPoolClientInput{
ClientId: aws.String(d.Id()),
UserPoolId: aws.String(d.Get("user_pool_id").(string)),
ClientId: aws.String(d.Id()),
UserPoolId: aws.String(d.Get("user_pool_id").(string)),
EnableTokenRevocation: aws.Bool(d.Get("enable_token_revocation").(bool)),
}

if v, ok := d.GetOk("name"); ok {
Expand Down Expand Up @@ -453,7 +464,9 @@ func resourceAwsCognitoUserPoolClientUpdate(d *schema.ResourceData, meta interfa

log.Printf("[DEBUG] Updating Cognito User Pool Client: %s", params)

_, err := conn.UpdateUserPoolClient(params)
_, err := retryOnAwsCode(cognitoidentityprovider.ErrCodeConcurrentModificationException, func() (interface{}, error) {
return conn.UpdateUserPoolClient(params)
})
if err != nil {
return fmt.Errorf("error updating Cognito User Pool Client (%s): %w", d.Id(), err)
}
Expand Down
Loading