【问题标题】:Terraform AWS Cognito App ClientTerraform AWS Cognito 应用程序客户端
【发布时间】:2018-05-20 13:33:02
【问题描述】:

目前陷入泥潭,试图通过 Terraform 为 AWS Cognito 用户池设置“应用程序客户端”。这是我的资源:

resource "aws_cognito_user_pool" "notes-pool" {
  name = "notes-pool"
  username_attributes = ["email"]

  verification_message_template {
    default_email_option = "CONFIRM_WITH_CODE"
  }

  password_policy {
    minimum_length    = 10
    require_lowercase = false
    require_numbers   = true
    require_symbols   = false
    require_uppercase = true
  }

  tags {
    "Name"    = "notes-pool"
    "Environment" = "production"
  }
}

以上工作正常,我的用户池已创建。如果有人对如何在同一资源中创建应用程序客户端有任何想法,我会全力以赴。我开始怀疑这个功能不存在!

【问题讨论】:

    标签: amazon-web-services amazon-cognito devops terraform


    【解决方案1】:

    我相信这只是添加到最新版本的 terraform 中。您可以执行以下操作将客户端添加到您的用户池:

     resource "aws_cognito_user_pool_client" "client" {
         name = "client"
         user_pool_id = "${aws_cognito_user_pool.pool.id}"
         generate_secret = true
         explicit_auth_flows = ["ADMIN_NO_SRP_AUTH"]
     }
    

    请参阅此处获取文档:Terraform entry on aws_cognito_user_pool_client

    【讨论】:

      【解决方案2】:

      更新 - 现在 terraform 支持。见@cyram's answer。 Terraform 目前不支持此功能。

      有一个open issue on GitHub 已请求此功能(如果您希望从此功能中受益,请点赞)。

      在添加支持之前,最好的选择是在创建资源后使用 local-exec 配置器通过 CLI 创建用户池:

      resource "aws_cognito_user_pool" "notes-pool" {
        name = "notes-pool"
      
        username_attributes = ["email"]
        ...
      
        provisioner "local-exec" {
          command = <<EOF
      aws cognito-idp create-user-pool-client \
        --user-pool-id ${aws_cognito_user_pool.notes-pool.id} \
        --client-name client-name \
        --no-generate-secret \
        --explicit-auth-flows ADMIN_NO_SRP_AUTH
      EOF
        }
      }
      

      请注意,要使用它,您必须安装 AWS CLI 并进行身份验证(我使用环境变量通过 Terraform 和 AWS CLI 进行身份验证)。

      【讨论】:

        【解决方案3】:

        创建用户池后,您可以使用 create-user-pool-client API 在用户池中创建 app-client。请参考API文档:https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPoolClient.html

        【讨论】:

        • 这个问题是关于 Terraform 提供者的,所以 API 在这里没有用处。
        猜你喜欢
        • 2021-08-24
        • 2021-11-08
        • 2020-10-23
        • 1970-01-01
        • 2022-01-13
        • 2019-06-11
        • 2020-09-11
        • 2023-03-05
        • 2020-04-19
        相关资源
        最近更新 更多