Concat 由 cidrsubnet 分配的两个值?

Concat on two values assigned by cidrsubnet?

我正在尝试将两个子网列表连接到 module.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.vpc.public_subnets 中就可以了:

  public_subnets = [
    for num in range(length(local.azs)) :
    cidrsubnet(local.cidr, 8, num + 10)
  ]

concat不是我需要的功能吗?对 Terraform 很陌生,非常感谢所有帮助。

concat returns 一个列表。所以假设你的 concat 确实有效,它应该是:

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  ...
  public_subnets = concat(local.ext_a_subnets,local.ext_b_subnets)
  ...
}