Hi, I’m a bit lost with the RouteTable function. I...
# golang
j
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{
				&ec2.RouteTableRouteArgs{
					CidrBlock: subnet.CidrBlock
and
subnet.CidrBlock
is from
[]*ec2.Subnet
. When I’m doing
fmt.Println()
on it, I see
{0xc0003c93b0}
.
b
That looks like a pointer address? Try using the pointer value with &
j
I tried it and it’s the same:
Copy code
"" is not a valid CIDR block
somehow it’s empty 😕
b
How are you populating it?
j
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{
				&ec2.RouteTableRouteArgs{
					CidrBlock: &subnet.CidrBlock,
					GatewayId: n.InternetGateway.ID(),
				}, (...)
b
why is
PrivateSubnets
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
j
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 😕
g
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