【问题标题】:Terraform: how to use the results of the Lambda invocation somewhere else?Terraform:如何在其他地方使用 Lambda 调用的结果?
【发布时间】:2020-01-19 09:24:07
【问题描述】:

我有一个 lambda,它在 terraform apply 期间被很好地调用,我从中得到了很好的输出:

output "out_params_map" {
  description = "something"
  value = module.get_params.result_map
}

它显示正确的结果

terraform apply...
...
Outputs: 

out_params_map = [
  {
    "key1" = "val1"
    "key2" = "val2"
  },
]

当我尝试像这样在其他地方使用输出时

resource "aws_security_group_rule" "this" {
  some_param = module.get_params.result_map.key1
}

terraform planterraform apply 均失败:

Error: Unsupported attribute

  on file.tf line 32, in resource "aws_security_group_rule" "this":
  32:   some_param = module.get_params.result_map.key1
    |----------------
    | module.get_params.result_map is empty tuple

This value does not have any attributes.

我也试过了:

... = module.get_params.result_map[0].key1
... = jsondecode(module.get_params.result)["key1"]
... = module.get_params.result_map["key1"]

但它也不起作用。

更多代码可以在这里找到:https://pastebin.com/rQaDJstU

那么,如何在其他地方使用调用的结果?

【问题讨论】:

  • 你能展示一个完全可行的minimal reproducible example吗?从您在这里的更简单的示例中很难看出可能有什么问题。
  • @ydaetskcoR 很高兴,但您想看哪一部分?全套将包括 lambda 创建,我怀疑它是否有意义。另一方面,如果我省略了那部分,那么唯一的代码就是已经复制和粘贴的资源。
  • 您是如何获得module.get_params.result_map 的?无论它来自哪里,都可能是有用的部分。
  • @ydaetskcoR 添加了链接,如果需要更多详细信息,请告诉我。
  • @Putnik 你能找到解决方案吗?我面临着类似的问题。

标签: aws-lambda terraform terraform-provider-aws


【解决方案1】:

假设您在模块 M 中将输出变量定义为 V,那么您可以将其访问为

变量 = "${module.M.V}"

【讨论】:

  • 这不能回答问题。正如您从错误消息中看到的那样,他们已经尝试过了。
  • 在 v0.12 中,您不必使用“${..}”,只需使用变量名。
猜你喜欢
  • 2018-09-10
  • 2021-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
  • 2021-08-04
相关资源
最近更新 更多