我正在使用 terraform v.0.11.7。
我想创建 4 个子网(2 个公共子网,2 个私有子网)
这是 vars.tf 的内容
variable "region" {
default = "ap-south-1"
}
variable "ami_id" {
type = "map"
default = "ami-d783a9b8"
}
variable "credentials" {
default = "/root/.aws/credentials"
}
variable "vpc_cidr" {
default = "10.0.0.0/16"
}
variable "pub_subnet_aza_cidr" {
default = "10.0.10.0/24"
}
variable "pub_subnet_azc_cidr" {
default = "10.0.20.0/24"
}
variable "pri_subnet_aza_cidr" {
default = "10.0.30.0/24"
}
variable "pri_subnet_azc_cidr" {
default = "10.0.40.0/24"
}
现在在 main.tf 中,我想将前 2 个公共子网关联到公共路由表,该怎么做?
resource "aws_subnet" "pub_subnet_aza" {
vpc_cidr = "{aws_vpc.vpc.id}"
cidr_block = "${var.pub_subnet_aza_cidr}"
tags {
Name = "Pub-Sunet-A"
}
availability_zone = "${data.aws_availability_zone.available.name[0]}"
}
resource "aws_subnet" "pub_subnet_azc" {
vpc_cidr = "{aws_vpc.vpc.id}"
cidr_block = "${var.pub_subnet_azc_cidr}"
tags {
Name = "Pub-Subnet-C"
}
availability_zone = "${data.aws_availability_zone.available.name[2]}"
}
resource "aws_route_table_association" "public" {
subnet_id = "${aws_subnet.pub_subnet_aza.id}" # How to put pub_subnet_azc.id into here?
route_table_id = "${aws_route_table.public.id}"
}