Amazon web services 将NAT网关地形化以设置路由表
我试图在我的路由表中设置我的私有多NAT网关,但我对我缺少的内容感到困惑。有人能帮我写下我丢失的代码吗 这是我的路线表:Amazon web services 将NAT网关地形化以设置路由表,amazon-web-services,terraform,aws-nat-gateway,Amazon Web Services,Terraform,Aws Nat Gateway,我试图在我的路由表中设置我的私有多NAT网关,但我对我缺少的内容感到困惑。有人能帮我写下我丢失的代码吗 这是我的路线表: resource "aws_route_table" "private" { count = length(var.private_subnet_cidr_blocks) vpc_id = aws_vpc.main_vpc.id route {
resource "aws_route_table" "private" {
count = length(var.private_subnet_cidr_blocks)
vpc_id = aws_vpc.main_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat-gw[count.index].id
}
tags = {
Name = "private-rtable-${count.index+1}"
}
}
resource "aws_route_table_association" "private" {
count = length(var.private_subnet_cidr_blocks)
subnet_id = element(aws_subnet.private.*.id, count.index)
route_table_id = element(aws_route_table.private.*.id, count.index)
}
这是我的NAT EIP和NAT网关:
resource "aws_eip" "nat-eip" {
count = length(data.aws_availability_zones.available.names)
vpc = true
}
resource "aws_nat_gateway" "nat-gw" {
count = length(data.aws_availability_zones.available.names)
allocation_id = element(aws_eip.nat-eip.*.id, count.index)
subnet_id = element(aws_subnet.public.*.id, count.index)
tags = {
Name = "NAT-GW-${count.index+1}"
}
}
我以前想将每个NAT网关连接到目的地为0.0.0.0/0的路由表,但这无法实现。有没有一种方法可以让您的NAT网关在您的体系结构中具有高可用性,或者您应该只连接一个NAT网关?如果是这样的话,我需要输入什么才能使它在Terraform中只连接一个NAT网关?非常感谢您的帮助
更新:
对于任何对此场景有疑问的人,我更新了其他正在寻找答案的人的代码。aws\u route\u表中的以下内容不正确。private:
count = var.private_subnet_cidr_blocks
应该是:
count = length(var.private_subnet_cidr_blocks)
route_table_id = element(aws_route_table.private.*.id, count.index)
另外,您的aws\u路线\u表格\u关联。专用而不是:
route_table_id = aws_route_table.private.id
应该有:
count = length(var.private_subnet_cidr_blocks)
route_table_id = element(aws_route_table.private.*.id, count.index)
原因是您将拥有与您的专用子网一样多的路由表。非常感谢!我知道我很快就把它弄好了,但你帮了我。真的非常感谢!。