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

[Enhancement]: aws_cognito_user_pool: enable lambda_version for pre_token_generation #35007

Closed
lorchda opened this issue Dec 20, 2023 · 7 comments · Fixed by #35236
Closed

[Enhancement]: aws_cognito_user_pool: enable lambda_version for pre_token_generation #35007

lorchda opened this issue Dec 20, 2023 · 7 comments · Fixed by #35236
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cognitoidp Issues and PRs that pertain to the cognitoidp service.
Milestone

Comments

@lorchda
Copy link

lorchda commented Dec 20, 2023

Terraform Core Version

1.5.3

AWS Provider Version

5.31.0

Affected Resource(s)

  • aws_cognito_user_pool

Expected Behavior

Amazon Cognito introduced a new User pool trigger version V2_0 for the pre token generation Lambda:

In the AWS Console, this corresponds to:

  • V1_0 Basic features. Your user pool sends a version 1 event to your Lambda function. You can customize identity tokens.
  • V2_0 Basic features + access token customization - Recommended. Your user pool sends a version 2 event to your Lambda function. You can customize identity and access tokens.

Expected behavior: I can use the new V2_0 event version.

Actual Behavior

The TF provider sets the default version V1_0.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_cognito_user_pool" "my_userpool" {
  name = var.userpool

  lambda_config {
    pre_token_generation = aws_lambda_function.pretokengeneration.arn
  }
  // ... other attributes removed for brevity
}

Steps to Reproduce

  1. Create aws_cognito_user_pool resource
  2. Set pre_token_generation attribute

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

Amazon Cognito introduced a new User pool trigger version V2_0 for the pre token generation Lambda:

Would you like to implement a fix?

None

@lorchda lorchda added the bug Addresses a defect in current functionality. label Dec 20, 2023
@github-actions github-actions bot added the service/cognitoidp Issues and PRs that pertain to the cognitoidp service. label Dec 20, 2023
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@terraform-aws-provider terraform-aws-provider bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 20, 2023
@SamuelCabralCruz
Copy link

In the meantime, I created a script that I execute as a post job once my infrastructure is deployed (terraform apply)

#!/usr/bin/env bash
set -euo pipefail

# TODO: temporary measure until https://github.com/hashicorp/terraform-provider-aws/issues/35007 is resolved

USER_POOL_NAME=<YOUR_USERPOOL_NAME>

USER_POOL_ID=$(aws cognito-idp list-user-pools --max-results 1 --query "UserPools[?Name=='${USER_POOL_NAME}'].Id" --output json | jq -r '.[0]')

CURRENT_CONFIG=$(aws cognito-idp describe-user-pool --user-pool-id "${USER_POOL_ID}" | jq -r '.UserPool')
UPDATED_CONFIG=$CURRENT_CONFIG
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.Id)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.Name)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.Status)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.Arn)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.CreationDate)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.LastModifiedDate)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.CustomDomain)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.Domain)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.EmailConfigurationFailure)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.SmsConfigurationFailure)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.EstimatedNumberOfUsers)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.SchemaAttributes)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.UsernameAttributes)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.UsernameConfiguration)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq 'del(.AdminCreateUserConfig)')
UPDATED_CONFIG=$(echo "${UPDATED_CONFIG}" | jq '.LambdaConfig.PreTokenGenerationConfig.LambdaVersion = "V2_0"')

aws cognito-idp update-user-pool --user-pool-id "${USER_POOL_ID}" --cli-input-json "${UPDATED_CONFIG}"

References:

@justinretzolk justinretzolk added enhancement Requests to existing resources that expand the functionality or scope. and removed bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jan 11, 2024
@justinretzolk
Copy link
Member

Hey @lorchda 👋 Thank you for taking the time to raise this! As a heads up, we consider adding additional functionality to existing resources to be an enhancement, so I've adjusted the labels as such.

@justinretzolk justinretzolk changed the title [Bug]: aws_cognito_user_pool: enable lambda_version for pre_token_generation [Enhancement]: aws_cognito_user_pool: enable lambda_version for pre_token_generation Jan 11, 2024
@AndresMorelos
Copy link
Contributor

Hey @justinretzolk 👋🏾 I made the PR #35236 adding this enhancement, could you please take a look and give me feedback if needed?

@egalev
Copy link

egalev commented Feb 22, 2024

In the meantime, I created a script that I execute as a post job once my infrastructure is deployed (terraform apply)

Thanks for the reference @SamuelCabralCruz, I used a shorter version of what you posted, if it helps anyone. Also changed PreTokenGenerationConfig to support an existing legacy config of PreTokenGeneration (the LambdaArn attribute must match)

CURRENT_COGNITO_CONFIG=$(aws cognito-idp describe-user-pool --user-pool-id "${USER_POOL_ID}" | jq -r '.UserPool')
# Strip the config, as described in https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-updating.html#cognito-user-pool-updating-api-cli
STRIPPED_COGNITO_CONFIG=$(echo "${CURRENT_COGNITO_CONFIG}" | jq 'del(.Arn, .CreationDate, .CustomDomain, .Domain, .EmailConfigurationFailure, .EstimatedNumberOfUsers, .Id, .LastModifiedDate, .Name, .SchemaAttributes, .SmsConfigurationFailure, .Status, .AliasAttributes, .AdminCreateUserConfig.UnusedAccountValidityDays)')
UPDATED_COGNITO_CONFIG=$(echo "${STRIPPED_COGNITO_CONFIG}" | jq '.LambdaConfig.PreTokenGenerationConfig = {"LambdaVersion": "V2_0", "LambdaArn": .LambdaConfig.PreTokenGeneration}')

aws cognito-idp update-user-pool --user-pool-id "${USER_POOL_ID}" --cli-input-json "${UPDATED_COGNITO_CONFIG}"

@github-actions github-actions bot added this to the v5.41.0 milestone Mar 13, 2024
Copy link

This functionality has been released in v5.41.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

I'm going to lock this issue 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 similar to this, 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 Apr 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/cognitoidp Issues and PRs that pertain to the cognitoidp service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants