0
votes

I'm trying to create vpc with two subnets: one public with internet gateway and one private that can only communicate with other local resource.

i had no problem creating the public route table:

resource "aws_route_table" "HW2-public-crt" {
vpc_id = "${aws_vpc.hw2_vpc.id}"

route {
    //associated subnet can reach everywhere
    cidr_block = "0.0.0.0/0" 
    //CRT uses this IGW to reach internet
    gateway_id = "${aws_internet_gateway.hw2-igw.id}" 

but when I tried to create the private route table:

resource "aws_route_table" "HW2-private-crt" {
vpc_id = "${aws_vpc.hw2_vpc.id}"
route {
cidr_block = "10.0.0.0/16" 

I get this error:

"Error creating route: MissingParameter: The request must contain exactly one of gatewayId, natGatewayId, networkInterfaceId, vpcPeeringConnectionId, egressOnlyInternetGatewayId, transitGatewayId or instanceId status code: 400"

when creating a route table in the console I don't see such requirement any thoughts?

1
where is your gateway_id? - Lamanus
gateway_id - (Optional) Identifier of a VPC internet gateway or a virtual private gateway. I don't want internet access, not sure what is virtual private gateway... - Asaf
when I removed cidr_block = "10.0.0.0/16" it let me complete the plan without errors... - Asaf

1 Answers

0
votes

You're receiving the error because trying to create a route within the route table without telling it the route.

If you don't want to route outside the subnet:

Note that the default route, mapping the VPC's CIDR block to "local", is created implicitly and cannot be specified.

If you do want to create a route outside of local:

The route argument (which is optional and why the command worked when you removed it) requires a cidr_block and one of the following:

  • egress_only_gateway_id
  • gateway_id
  • instance_id
  • nat_gateway_id
  • network_interface_id
  • transit_gateway_id
  • vpc_peering_id

The list above is the path you'd be routed to when matching the cidr_block of the route.

References

route_table .