![](/img/trans.png)
[英]How to pass values from the Terraform output without putting it in the tfvars file
[英]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
但我收到這個錯誤......
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.