terraform - Terraform,计数时列出错误的字符串
问题描述
我正在尝试制作一个通过循环创建 Azure 路由的 Terraform 剧本。
最终目标是用户将在逗号分隔列表中输入他们的目的地。例如:
Enter route destinations: 0.0.0.0/0,192.168.0.0/16
azurerm_route 将通过此变量运行此函数并创建路由。
variable "destinations" {
default = "0.0.0.0/0,192.168.0.0/16"
}
resource "azurerm_route" "route" {
name = "route-${count.index}"
resource_group_name = "resourcegroup"
route_table_name = "table"
address_prefix = "${split(",", var.destinations)}[count.index]"
next_hop_type = "Internet"
count = "${length(split(",", var.destinations))}"
}
但是,我在通过前缀列表计数时遇到问题,并且收到以下错误:
* azurerm_route.route[1]: At column 1, line 1: output of an HIL
expression must be a string, or a single list (argument 1 is
TypeList) in:
${split(",", var.destinations)}[count.index]
* azurerm_route.route[0]: At column 1, line 1: output of an HIL
expression must be a string, or a single list (argument 1 is
TypeList) in:
${split(",", var.destinations)}[count.index]
解决方案
弄清楚了。您必须使用元素插值。
resource "azurerm_route" "route" {
name = "route-${count.index}"
resource_group_name = "resourcegroup"
route_table_name = "table"
address_prefix = "${element(split(",",var.destinations),count.index)}"
next_hop_type = "Internet"
count = "${length(split(",",var.destinations))}"
}
推荐阅读
- excel - 为什么我不能这样声明我的类对象?
- c# - System.Net.IPAddress.Parse() 将(不需要的)IPv6 字符串转换为 IPv4 映射到 IPv6 地址
- python - 在悬停模板中绘制python散点图矩阵列名
- sed - sed:每句后加分号
- discord - Discord Bot Webhook 可以在 discord 上 iplogger 人
- spss - 中介分析(SPSS 或 AMOS),包括控制和二元变量
- python-requests - 需要将 response.text 转换为数组列表
- c++ - 如何将中文/韩文单词导出到csv
- azure - Blob created 和 Blob 重命名有什么区别?
- python - 如何重新排序字符串的字符