Hi, I’m a bit lost with the RouteTable function. I...
# golang
Hi, I’m a bit lost with the RouteTable function. I’m trying to create a RouteTable and I’m getting
as a CidrBlock. Not sure why. This is my code:
Copy code
routeTable, err := ec2.NewRouteTable(ctx, n.genUniqName("route-private", i), &ec2.RouteTableArgs{
			VpcId: n.VPC.ID(),
			Routes: ec2.RouteTableRouteArray{
					CidrBlock: subnet.CidrBlock
is from
. When I’m doing
on it, I see
That looks like a pointer address? Try using the pointer value with &
I tried it and it’s the same:
Copy code
"" is not a valid CIDR block
somehow it’s empty 😕
How are you populating it?
I have a struct:
Copy code
type Subnets struct {
	PrivateSubnets []*ec2.Subnet (...)
and method:
Copy code
func (n *Networking) createPrivateSubnets(ctx *pulumi.Context, input types.Subnets) error {
	for i, private := range input.Private {
		subnetName := n.subnetNameGen("private", i)
		subnet, err := ec2.NewSubnet(ctx, subnetName, &ec2.SubnetArgs{
			VpcId:     n.VPC.ID(),
			CidrBlock: private.ToStringPtrOutput(),
			Tags: pulumi.StringMap{
				"Name": pulumi.String(subnetName),
		}, pulumi.Parent(n))
		if err != nil {
			return err

		n.Subnets.PrivateSubnets = append(n.Subnets.PrivateSubnets, subnet)

	return nil
and then I’m trying to use it like:
Copy code
func (n *Networking) createPrivateRoutes(ctx *pulumi.Context) error {
	for i, subnet := range n.Subnets.PrivateSubnets {
		routeTable, err := ec2.NewRouteTable(ctx, n.genUniqName("route-public", i), &ec2.RouteTableArgs{
			VpcId: n.VPC.ID(),
			Routes: ec2.RouteTableRouteArray{
					CidrBlock: &subnet.CidrBlock,
					GatewayId: n.InternetGateway.ID(),
				}, (...)
why is
a pointer? it has been a long time since I did this, but this worked: https://github.com/jaxxstorm/jen20-pulumi-aws-vpc/blob/go/go/main.go#L128-L149
Strange, my code looks almost the same. I cannot track the issue. Anyway, thanks! I will try to work on it tomorrow. Probably something small but I cannot catch it 😕
Hi @jolly-church-88521 , have you tried create a VPC then add route to it default route table? I think you might have tried it