- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下用于 cognito 客户端的 terraform 配置:
data "aws_cognito_user_pools" "re_user_pool" {
name = "${var.cognito_user_pool_name}"
}
resource "aws_cognito_user_pool_client" "app_client" {
name = "re-app-client"
user_pool_id = data.aws_cognito_user_pools.re_user_pool.id
depends_on = [data.aws_cognito_user_pools.re_user_pool]
explicit_auth_flows = ["USER_PASSWORD_AUTH"]
prevent_user_existence_errors = "ENABLED"
allowed_oauth_flows_user_pool_client = true
allowed_oauth_flows = ["code"]
allowed_oauth_scopes = ["phone", "openid", "email", "profile", "aws.cognito.signin.user.admin"]
supported_identity_providers = ["COGNITO", "Google"]
callback_urls = ["https://scnothzsf0.execute-api.ap-southeast-2.amazonaws.com/staging/signup"]
}
我引用了 AWS 上已经存在的 Cognito 用户池。当它使用 aws_cognito_user_pool_client
中的用户池 ID 时,错误发生在 user_pool_id = data.aws_cognito_user_pools.re_user_pool.id
行。我会得到错误
Error: Error creating Cognito User Pool Client: InvalidParameterException: 1 validation error detected: Value 're-user' at 'userPoolId' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w-]+_[0-9a-zA-Z]+
on infra/cognito.tf line 5, in resource "aws_cognito_user_pool_client" "app_client":
5: resource "aws_cognito_user_pool_client" "app_client" {`
ID 的格式似乎不正确。我已阅读此文档 https://www.terraform.io/docs/providers/aws/d/cognito_user_pools.html
并且它具有引用属性 ids - The list of cognito user pool ids.
.我想知道为什么它会提供一个用户池 ID 列表。我如何引用此 ID?
我还尝试将其引用为 user_pool_id = data.aws_cognito_user_pools.re_user_pool.ids[0]
但出现错误:
Error: Invalid index
on infra/cognito.tf line 8, in resource "aws_cognito_user_pool_client" "app_client":
8: user_pool_id = data.aws_cognito_user_pools.re_user_pool.ids[0]
This value does not have any indices.
上面引用的re_user_pool
定义在这里:
resource "aws_cognito_user_pool" "re_user_pool" {
name = "re-user"
}
最佳答案
我在解决同样的问题时遇到了你的问题。我看到这个问题已经有几个月了,但我仍然会为像我一样最终出现在这里的任何人添加一个答案。
首先,解决方案是通过tolist
将ids
值从set
转换为list
函数,然后像访问任何 terraform list
一样访问它。
警告:在我的例子中,我已确保我只有一个给定名称的用户池,但如果您没有遵循此约定,您可能会获得多个用户池。对于这种情况,此解决方案不是完整的解决方案,但也许它仍会指明正确的方向。
示例代码:
data "aws_cognito_user_pools" "test" {
name = "a_name"
}
output "test" {
value = "${tolist(data.aws_cognito_user_pools.test.ids)[0]"
}
其次,我是如何得出结论的:
我添加了一个 output
block ,这样我就可以看到我正在使用什么,并且我在我的 terraform 文件中注释掉了有问题的行,这样我就可以成功地执行 terraform apply
。接下来我运行 terraform apply
然后是 terraform output --json
(注意:apply
必须成功才能 output
以获得最新值)。
示例临时输出 block :
output "test" {
value = "${data.aws_cognito_user_pools.test}" // output top-level object for debugging
}
相关terraform应用
输出:
test = {
"arns" = [
"<redacted>",
]
"id" = "a_name"
"ids" = [
"us-east-1_<redacted>",
]
"name" = "a_name"
}
相关terraform输出--json
输出:
"test": {
"sensitive": false,
"type": [
"object",
{
"arns": [
"set",
"string"
],
"id": "string",
"ids": [
"set",
"string"
],
"name": "string"
}
],
"value": {
"arns": [
"<redacted>"
],
"id": "a_name",
"ids": [
"us-east-1_<redacted>"
],
"name": "a_name"
}
}
如您所见,ids
部分是 string
类型的 set
。我决定尝试将 ids
转换为列表,看看我是否可以访问 0
索引并且它有效。我觉得这可能是一个 terraform 错误,但我还没有提交问题。
关于terraform - 如何在 `Terraform` 中引用 aws_cognito_user_pools id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61434636/
我有以下用于 cognito 客户端的 terraform 配置: data "aws_cognito_user_pools" "re_user_pool" { name = "${var.cog
我是一名优秀的程序员,十分优秀!