[英]for_each for a list of strings
I am creating a variable in terraform cloud and using that variable as an input to create a random_pet
resource.我正在 terraform 云中创建一个变量,并使用该变量作为输入来创建一个
random_pet
资源。
resource "tfe_variable" "names" {
key = "name_prefixes"
value = jsonencode(yamldecode(file("names_list.yaml")))
workspace_id = "ws-id"
hcl = true
category = "terraform"
}
resource "random_pet" "pet" {
for_each = toset(tfe_variable.names.key)
prefix = each.key
}
cat names_list.yaml
---
- "tfe"
- "tfc"
- "ansible"
- "puppet"
I am getting an error:我收到一个错误:
Error: Invalid function argument
on main.tf line 12, in resource "random_pet" "pet":
for_each = toset(tfe_variable.names.key)
Invalid value for "v" parameter: cannot convert string to set of any single type.
Can you please suggest?你能建议吗?
You have only one instance of tfe_variable.names
.您只有一个
tfe_variable.names
实例。 Thus, there is nothing to iterate over.因此,没有什么可以迭代的。 So you should just have:
所以你应该有:
resource "random_pet" "pet" {
prefix = tfe_variable.names.key
}
UPDATE更新
resource "tfe_variable" "names" {
key = "name_prefixes"
value = jsonencode(yamldecode(file("names_list.yaml")))
workspace_id = "ws-id"
hcl = true
category = "terraform"
}
resource "random_pet" "pet" {
for_each = toset(yamldecode(file("names_list.yaml")))
prefix = each.value
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.