我使用模块" vpc“创建了一个vpc,请说明如何在”应用“之后用子网ID分配变量private_subnets或public_subnets,但我的问题是,在”资源“块中,这些变量被分配给CIDR块。
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
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"]
enable_nat_gateway = true
enable_vpn_gateway = true
tags = {
Terraform = "true"
Environment = "dev"
}
}发布于 2022-07-14 16:59:11
一个模块包含多个资源,当您查看terraform-aws-模块/vpc/aws模块的代码时,您将看到private_subnets和public_subnets用于创建aws_subnet资源:
resource "aws_subnet" "private" {
count = local.create_vpc && length(var.private_subnets) > 0 ? length(var.private_subnets) : 0
vpc_id = local.vpc_id
cidr_block = var.private_subnets[count.index]
}https://stackoverflow.com/questions/72983985
复制相似问题