Tyler Norlund
Tyler Norlund

Reputation: 458

Terraform Cognito User Pool

I'd like to use email verification in my Cognito User Pool. When I apply my current config, it defaults to "No verification." How do I get it so that the email needs to be verified?

resource "aws_cognito_user_pool" "main" {
  name = "${var.user_pool_name}_${var.stage}"
  username_attributes = [ "email" ]
  schema {
    attribute_data_type = "String"
    mutable             = true
    name                = "name"
    required            = true
  }
  schema {
    attribute_data_type = "String"
    mutable             = true
    name                = "email"
    required            = true
  }

  password_policy {
    minimum_length    = "8"
    require_lowercase = true
    require_numbers   = true
    require_symbols   = true
    require_uppercase = true
  }
  mfa_configuration        = "OFF"

  lambda_config {
    custom_message    = aws_lambda_function.custom_message.arn
    post_confirmation = aws_lambda_function.post_confirmation.arn
  }
}

enter image description here

Upvotes: 1

Views: 1436

Answers (1)

samtoddler
samtoddler

Reputation: 9625

aws_cognito_user_pool

auto_verified_attributes attribute of aws_cognito_user_pool resource is a list of attributes that you want to enable verification for.

auto_verified_attributes - (Optional) The attributes to be auto-verified. Possible values: email, phone_number.

AutoVerifiedAttributes

resource "aws_cognito_user_pool" "main" {
  name = "${var.user_pool_name}_${var.stage}"
  auto_verified_attributes = ["email"]
  username_attributes = [ "email" ]
  schema {
    attribute_data_type = "String"
    mutable             = true
    name                = "name"
    required            = true
  }
  schema {
    attribute_data_type = "String"
    mutable             = true
    name                = "email"
    required            = true
  }

  password_policy {
    minimum_length    = "8"
    require_lowercase = true
    require_numbers   = true
    require_symbols   = true
    require_uppercase = true
  }
  mfa_configuration        = "OFF"

  lambda_config {
    custom_message    = aws_lambda_function.custom_message.arn
    post_confirmation = aws_lambda_function.post_confirmation.arn
  }
}

Upvotes: 3

Related Questions