我正在尝试将两个子网列表连接到模块.vpc.public_subnets 中
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
...
public_subnets = [
concat(local.ext_a_subnets,local.ext_b_subnets)
]
...
}
...
locals {
...
ext_a_subnets = [
for num in range(length(local.azs)) :
cidrsubnet(local.cidr, 8, num + 10)
]
ext_b_subnets = [
for num in range(length(local.azs)) :
cidrsubnet(local.cidr, 8, num)
]
...
}
当我运行terraform validate
时,我得到以下错误:
Error: Invalid value for module argument
on main.tf line 45, in module "vpc":
45: public_subnets = [
46: concat(local.ext_a_subnets,local.ext_b_subnets)
47: ]
The given value is not suitable for child module variable "public_subnets"
defined at .terraform/modules/vpc/variables.tf:151,1-26: element 0: string
required.
然而,将cidrsubnet for循环放在module.vp.public_subnets中可以直接工作:
public_subnets = [
for num in range(length(local.azs)) :
cidrsubnet(local.cidr, 8, num + 10)
]
concat不是我需要的函数吗?对地形很陌生,所以感谢所有的帮助。
concat返回一个列表。因此,假设您的concat
实际工作,它应该是:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
...
public_subnets = concat(local.ext_a_subnets,local.ext_b_subnets)
...
}