Попробуйте использовать formatlist , а затем join .
locals {
# this should give you
formatted_list = "${formatlist("SubnetId=%s,Ip=%s", var.subnet_list, var.cidrs_list}"
# combine the formatted list of parameter together using join
cli_parameter = "${join(" ", locals.formatted_list)}"
}
EDIT: вам нужно будет использовать null_resource
для преобразования CIDR в IP-адреса, напримерв другом ответе.Тогда вы можете просто построить formatted_list
и cli_parameter
аналогично предыдущему.
locals {
subnet_list = ["subnet-x","subnet-y","subnet-z"]
cidr_list = ["cidr-x","cidr-y","cidr-z"]
# this should give you
formatted_list = "${formatlist("SubnetId=%s,Ip=%s", var.subnet_list, null_resource.cidr_host_convert.*.triggers.value)}"
# combine the formatted list of parameter together using join
cli_parameter = "${join(" ", locals.formatted_list)}"
}
resource "null_resource" "cidr_host_convert" {
count = "${length(locals.cidr_list}"
trigger = {
# for each CIDR, get the first IP Address in it. You may need to manage
# the index value to prevent overlap
desired_ips = "${cidrhost(locals.cidr_list[count.index], 1)}"
}
}