【发布时间】:2016-11-28 14:46:54
【问题描述】:
我正在使用 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 邮件列表上问过这个问题,但我想我会尝试更多的受众。
谢谢, 蒂姆
【问题讨论】:
-
我不必这样做,所以我不能保证,但你可以尝试让命令将其输出重定向到一个文件(也许通过
sed发送它以提取您需要的确切值),然后在您需要输出的地方使用文件资源。然后确保在需要文件的资源中添加适当的depends_on属性,以确保它们在生成后运行。 -
另外,如果他们的 GItHub 存储库中还没有关于从
null_resource定义输出的功能请求,您可能需要打开一个。我相信其他人会发现它很有用,并且很有可能在未来的版本中实现它。 -
@tim_barber_7BB 你最终是怎么做到的?有人在这吗?
-
@Christine 我没有解决这个问题。我认为这将是该过程的手动部分(除非有人想出什么办法),目前我不会再花时间调查。
标签: amazon-web-services aws-cli amazon-cognito terraform