下面是一个示例的Terraform模板,用于创建AWS路由表:
provider "aws" {
region = "us-west-2"
}
resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-west-2a"
}
resource "aws_internet_gateway" "example" {
vpc_id = aws_vpc.example.id
}
resource "aws_route_table" "example" {
vpc_id = aws_vpc.example.id
}
resource "aws_route" "example" {
route_table_id = aws_route_table.example.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.example.id
}
resource "aws_subnet_route_table_association" "example" {
subnet_id = aws_subnet.example.id
route_table_id = aws_route_table.example.id
}
在这个示例中,我们通过Terraform创建了一个VPC、一个子网、一个Internet Gateway、一个路由表和一个路由。路由表与子网通过aws_subnet_route_table_association
资源进行关联。路由表中添加了一条默认路由,将流量转发到Internet Gateway。
你可以根据自己的需求修改这个模板,例如更改VPC的CIDR块、子网的CIDR块和可用区等。