I'm struggling to understand the difference between the following Terraform Resources:
Example 1:
resource "aws_route_table" "public_1" {
vpc_id = aws_vpc.test.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
tags = {
Name = "test-route"
}
}
resource "aws_route_table_association" "test_pub_route" {
subnet_id = aws_subnet.test_pub.id
route_table_id = aws_route_table.public_1.id
}
Correct me if I'm wrong but in this example I'm just creating a route and a route table with public_1
resource.
In the second part I'm just associating the public_1 route table subnet called test_pub.
Question 1:
I don't understand what does the block route do in public_1
The documentation here doesn't make much sense to me.
Example 2:
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
}
resource "aws_route" "public" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.test_pub.id
route_table_id = aws_route_table.public.id
}
Question 2(main)
I'm trying to understand if these two examples are actually the same. And that the only difference is that in the first example we have route block which is equivalent to resource aws_route in the second example.
Even the required variables are the same just name is little bit different.