1

我正在寻找一种方法来区分我的模块中的标签名称,并且知道那里有一个障碍,因为您不能在模块中使用计数,我想根据公众的位置增加我的标签名称子网,我该怎么做?

variable "public_subnet_count" {
    default = 3
}

variable "public_subnet_name" {
    default = {
        0 = "cp-net0"
        1 = "k8s-net0"
        2 = "um-net0"
    }
}

module "vpc" {
  source = "github.com/terraform-aws-modules/terraform-aws-vpc"
  name   = "apigee"

  cidr = "10.0.0.0/16"

  azs             = data.aws_availability_zones.available.names
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  assign_generated_ipv6_cidr_block = true

  enable_nat_gateway = true
  single_nat_gateway = true

  public_subnet_tags = {
    Name = lookup(var.public_subnet_name, count.index) // will not work
  }

  tags = {
    Owner       = "212743998"
    Environment = "sandbox"
  }

  vpc_tags = {
    Name = "apigee"
  }
}
4

0 回答 0