繁体   English   中英

在 Terraform 中,如何从列表中获取 output 的值?

[英]In Terraform, how to output values from a list?

我正在尝试获取 output 以显示正在创建的 IAM 用户的名称。

resource "aws_iam_user" "lb" {
    name = var.elb_names[count.index]
    count = 3
    path = "/system/"
}

variable "elb_names" {
    type = list
    default = ["dev-lb", "qa-lb", "prod-lb"]
}

output "elb_names" {
    value = aws_iam_user.lb.name[count.index]
}

我希望得到以下 output

  1. 开发lb
  2. qa-lb
  3. 产品磅

但我收到这个错误......

Error: Missing resource instance key
on countEC2.tf line 38, in output "elb_names":
38:     value = aws_iam_user.lb.name[count.index]

Because aws_iam_user.lb has "count" set, its attributes must be accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
aws_iam_user.lb[count.index]

您将不得不使用稍微不同的方法:

output "elb_names" {
    value = aws_iam_user.lb[*].name
}

这是splat表达式 [1]。 请注意,output 将是一个列表。


[1] https://developer.hashicorp.com/terraform/language/expressions/splat

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM