:wave: Hi everyone! I am using pulumi-aws, a new ...
# general
g
👋 Hi everyone! I am using pulumi-aws, a new guru, I found it is hard to find route table via ec2.GetRouteTable. any ideas, how to get the table and add a route to it?
f
what are you finding hard?. Are you trying to get an specific routeTable already created and then attach some routes?
g
yes
I created a VPC then add route to its default route table
the full scenario is 1. create ec2 instance 2. create vpc 3. create igw 4. link igw to vpc 5. add default route in vpc main route table, point to route table
but somehow I found it is is hard to understand the syntax,
Copy code
func GetRouteTable(ctx *pulumi.Context,
	name string, id pulumi.IDInput, state *RouteTableState, opts ...pulumi.ResourceOption) (*RouteTable, error) {
	var resource RouteTable
	err := ctx.ReadResource("aws:ec2/routeTable:RouteTable", name, id, state, &resource, opts...)
	if err != nil {
		return nil, err
	}
	return &resource, nil
}
here, I can get the route table id when I create vpc, like vpc.DefaultRouteTableId. but I am not sure how to convert it to id pulumi.IDInput @flaky-arm-38472
from my understanding, the flow should be find the route table(with table id), add route(src,dest)
I guess, I need to use GetDefaultRouteTable
instead of getroutetable
figured out
Copy code
_, err = ec2.NewRoute(ctx, "route", &ec2.RouteArgs{
		RouteTableId:         myVpc.DefaultRouteTableId,
		DestinationCidrBlock: pulumi.String("0.0.0.0/0"),
		GatewayId:            igw.ID(),
	}, pulumi.Parent(myVpc))