我正在使用 Terraform 在 AWS 中自动提供 Cognito 身份池。AWS 提供商还不支持 Cognito,所以我一直在使用 null_resource 和 local-exec 来调用 AWS CLI。
我有以下资源:
resource "null_resource" "create-identitypool" {
provisioner "local-exec" {
command = "aws cognito-identity create-identity-pool --identity-pool-name terraform_identitypool --no-allow-unauthenticated-identities --developer-provider-name login.terraform.myapp"
}
}
给出以下输出:
null_resource.create-identitypool (local-exec): {
null_resource.create-identitypool (local-exec): "IdentityPoolId": "eu-west-1:22549ad3-1611-......",
null_resource.create-identitypool (local-exec): "AllowUnauthenticatedIdentities": false,
null_resource.create-identitypool (local-exec): "DeveloperProviderName": "login.terraform.myapp",
null_resource.create-identitypool (local-exec): "IdentityPoolName": "terraform_identitypool"
null_resource.create-identitypool (local-exec): }
null_resource.create-identitypool: Creation complete
下一步是将我已经创建的一些角色添加到身份池中:
resource "null_resource" "attach-policies-identitypool" {
provisioner "local-exec" {
command = "aws cognito-identity set-identity-pool-roles --identity-pool-id ${null_resource.create-identitypool.IdentityPoolId} --roles authenticated=authroleXXX,unauthenticated=unauthroleXXX"
}
}
问题是我无法提取 IdentityPoolId ${null_resource.create-identitypool.IdentityPoolId} 以在第二个资源中使用。我知道 null_resource 没有输出属性,所以我怎样才能从命令行输出中获取这个 JSON 对象。我还想使用 tirggers 并运行 aws cognito-identity list-identity-pools 和可能的 delete-identity-pool 以使这一切都可以重复,我还需要输出。
有任何想法吗?如果我在其他地方错过了这些信息,我们深表歉意。我也在 Terraform 邮件列表上问过这个问题,但我想我会尝试更广泛的受众。
谢谢,蒂姆