diff --git a/aws/resource_aws_cognito_user_pool.go b/aws/resource_aws_cognito_user_pool.go index 095664dbe34..5f24243e401 100644 --- a/aws/resource_aws_cognito_user_pool.go +++ b/aws/resource_aws_cognito_user_pool.go @@ -198,6 +198,11 @@ func resourceAwsCognitoUserPool() *schema.Resource { Optional: true, ValidateFunc: validateArn, }, + "pre_token_generation": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, + }, "verify_auth_challenge_response": { Type: schema.TypeString, Optional: true, diff --git a/aws/resource_aws_cognito_user_pool_test.go b/aws/resource_aws_cognito_user_pool_test.go index a2c3aa071d9..825bbac6fb0 100644 --- a/aws/resource_aws_cognito_user_pool_test.go +++ b/aws/resource_aws_cognito_user_pool_test.go @@ -346,6 +346,7 @@ func TestAccAWSCognitoUserPool_withLambdaConfig(t *testing.T) { resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.post_confirmation"), resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.pre_authentication"), resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.pre_sign_up"), + resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.pre_token_generation"), resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.verify_auth_challenge_response"), ), }, @@ -360,6 +361,7 @@ func TestAccAWSCognitoUserPool_withLambdaConfig(t *testing.T) { resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.post_confirmation"), resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.pre_authentication"), resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.pre_sign_up"), + resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.pre_token_generation"), resource.TestCheckResourceAttrSet("aws_cognito_user_pool.main", "lambda_config.0.verify_auth_challenge_response"), ), }, @@ -792,6 +794,7 @@ resource "aws_cognito_user_pool" "main" { post_confirmation = "${aws_lambda_function.main.arn}" pre_authentication = "${aws_lambda_function.main.arn}" pre_sign_up = "${aws_lambda_function.main.arn}" + pre_token_generation = "${aws_lambda_function.main.arn}" verify_auth_challenge_response = "${aws_lambda_function.main.arn}" } }`, name) @@ -845,6 +848,7 @@ resource "aws_cognito_user_pool" "main" { post_confirmation = "${aws_lambda_function.second.arn}" pre_authentication = "${aws_lambda_function.second.arn}" pre_sign_up = "${aws_lambda_function.second.arn}" + pre_token_generation = "${aws_lambda_function.second.arn}" verify_auth_challenge_response = "${aws_lambda_function.second.arn}" } }`, name) diff --git a/aws/structure.go b/aws/structure.go index f4261153efc..67a27676904 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -2305,6 +2305,10 @@ func expandCognitoUserPoolLambdaConfig(config map[string]interface{}) *cognitoid configs.PreSignUp = aws.String(v.(string)) } + if v, ok := config["pre_token_generation"]; ok && v.(string) != "" { + configs.PreTokenGeneration = aws.String(v.(string)) + } + if v, ok := config["verify_auth_challenge_response"]; ok && v.(string) != "" { configs.VerifyAuthChallengeResponse = aws.String(v.(string)) } @@ -2347,6 +2351,10 @@ func flattenCognitoUserPoolLambdaConfig(s *cognitoidentityprovider.LambdaConfigT m["pre_sign_up"] = *s.PreSignUp } + if s.PreTokenGeneration != nil { + m["pre_token_generation"] = *s.PreTokenGeneration + } + if s.VerifyAuthChallengeResponse != nil { m["verify_auth_challenge_response"] = *s.VerifyAuthChallengeResponse } diff --git a/examples/cognito-user-pool/main.tf b/examples/cognito-user-pool/main.tf index 77ba20db4e9..74c65c62f0d 100644 --- a/examples/cognito-user-pool/main.tf +++ b/examples/cognito-user-pool/main.tf @@ -1,5 +1,6 @@ resource "aws_iam_role" "main" { name = "terraform-example-lambda" + assume_role_policy = <