Terraform:如何在其他地方使用Lambda调用的结果?

时间:2019-09-18 12:07:40

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

我有一个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

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

1 个答案:

答案 0 :(得分:0)

假设您在模块M中将输出变量定义为V,然后可以通过

进行访问
  

variable =“ $ {module.M.V}”