使用 Terraform 为 AWS Cognito 用户池设置账户恢复首选项
Set account recovery preference for AWS Cognito User Pool with Terraform
本着基础设施即代码的精神,我通过 Terraform 使用有用的 aws_cognito_user_pool
资源配置了 AWS Cognito 用户池。
但是,我似乎无法在 MFA 和验证 部分下找到帐户恢复首选项的 argument/config 映射。
没有说明,这似乎是我的默认选择:
(Not Recommended) Phone if available, otherwise email, and do allow a user to reset their password via phone if they are also using it for MFA.
目标
我想将其设置为 Email only
,如下图中的红色矩形所示:
有人知道我需要使用什么 Terraform 参数来实现这个吗? aws_cognito_user_pool
资源中记录的 None 个选项似乎映射到此。
Terraform 尚不支持。
但是您可以改用本地执行程序:
resource "null_resource" "setup_account_recovery_settings" {
triggers = {
version = "${var.version_local_exec_account_recovery_settings}"
}
provisioner "local-exec" {
command = "aws cognito-idp update-user-pool --user-pool-id ${aws_cognito_user_pool.userpool.id} --account-recovery-setting 'RecoveryMechanisms=[{Priority=1,Name=verified_email},{Priority=2,Name=verified_phone_number}]' --region ${var.region}"
}
}
但它会抹掉你的整个配置。相反,您可以提供完整配置作为 json 但为什么要使用 terraform 而不是
按照大卫的想法,如果你想启用"email only"选项,你应该设置
--account-recovery-setting 'RecoveryMechanisms=[{Priority=1,Name=verified_email}]'
此致,
您好Peter,我正在使用 CloudFormation 模板创建 Cognito 配置。
稍作修改并转换为 YAML。我们可以将 恢复设置设置为仅电子邮件 选项。请找到以下代码片段。
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: "test-pool"
UsernameAttributes: [email]
AccountRecoverySetting:
RecoveryMechanisms:
- Name: "verified_email"
Priority: 1
AutoVerifiedAttributes:
- email
这似乎对我有用:)
注意:在尝试合并 "admin_only" 的其他选项时,AWS 生成错误 无效的帐户恢复设置参数。帐户恢复设置不能将 admin_only 设置与任何其他恢复机制一起使用。
1 年过去了,由于新引入的设置 account_recovery_setting, of the aws_cognito_user_pool 资源,我现在可以回答自己的问题了。
例如,要将帐户恢复首选项设置为仅限电子邮件,我们可以执行以下操作:
resource "aws_cognito_user_pool" "mypool" {
name = "mypool"
account_recovery_setting {
recovery_mechanism {
name = "verified_email"
priority = 1
}
}
}
自 v3.19.0 of the AWS provider, as part of this merged PR 起可用。
本着基础设施即代码的精神,我通过 Terraform 使用有用的 aws_cognito_user_pool
资源配置了 AWS Cognito 用户池。
但是,我似乎无法在 MFA 和验证 部分下找到帐户恢复首选项的 argument/config 映射。
没有说明,这似乎是我的默认选择:
(Not Recommended) Phone if available, otherwise email, and do allow a user to reset their password via phone if they are also using it for MFA.
目标
我想将其设置为 Email only
,如下图中的红色矩形所示:
有人知道我需要使用什么 Terraform 参数来实现这个吗? aws_cognito_user_pool
资源中记录的 None 个选项似乎映射到此。
Terraform 尚不支持。 但是您可以改用本地执行程序:
resource "null_resource" "setup_account_recovery_settings" {
triggers = {
version = "${var.version_local_exec_account_recovery_settings}"
}
provisioner "local-exec" {
command = "aws cognito-idp update-user-pool --user-pool-id ${aws_cognito_user_pool.userpool.id} --account-recovery-setting 'RecoveryMechanisms=[{Priority=1,Name=verified_email},{Priority=2,Name=verified_phone_number}]' --region ${var.region}"
}
}
但它会抹掉你的整个配置。相反,您可以提供完整配置作为 json 但为什么要使用 terraform 而不是
按照大卫的想法,如果你想启用"email only"选项,你应该设置
--account-recovery-setting 'RecoveryMechanisms=[{Priority=1,Name=verified_email}]'
此致,
您好Peter,我正在使用 CloudFormation 模板创建 Cognito 配置。
稍作修改并转换为 YAML。我们可以将 恢复设置设置为仅电子邮件 选项。请找到以下代码片段。
UserPool:
Type: "AWS::Cognito::UserPool"
Properties:
UserPoolName: "test-pool"
UsernameAttributes: [email]
AccountRecoverySetting:
RecoveryMechanisms:
- Name: "verified_email"
Priority: 1
AutoVerifiedAttributes:
- email
这似乎对我有用:)
注意:在尝试合并 "admin_only" 的其他选项时,AWS 生成错误 无效的帐户恢复设置参数。帐户恢复设置不能将 admin_only 设置与任何其他恢复机制一起使用。
1 年过去了,由于新引入的设置 account_recovery_setting, of the aws_cognito_user_pool 资源,我现在可以回答自己的问题了。
例如,要将帐户恢复首选项设置为仅限电子邮件,我们可以执行以下操作:
resource "aws_cognito_user_pool" "mypool" {
name = "mypool"
account_recovery_setting {
recovery_mechanism {
name = "verified_email"
priority = 1
}
}
}
自 v3.19.0 of the AWS provider, as part of this merged PR 起可用。