https://pulumi.com logo
Title
h

hundreds-yacht-71603

01/09/2023, 6:42 PM
Hmmm I'm using aws-native provider. I can lookup a vpc, easy. But I'm having a hard time finding out how to go from this VPC to the subnets and their CIDR ranges. Any hints?
m

miniature-musician-31262

01/09/2023, 6:46 PM
Maybe this example could help? It shows looking up.a VPC and then using it to provision other resources. If not, maybe you could share a little code that shows more what you’re running into.
h

hundreds-yacht-71603

01/09/2023, 6:49 PM
Hmmm,
// Note: Some resources are not yet supported by the Native AWS provider, so we are using both the Native
// and Classic provider in this example. The resources will be updated to use native resources as they are
// available in AWS's Cloud Control API.

const defaultVpc = aws.ec2.getVpcOutput({default: true});
const defaultVpcSubnets = aws.ec2.getSubnetIdsOutput({vpcId: defaultVpc.id});
It seems these are the 2 lines, but they are from the classic provider 😞
m

miniature-musician-31262

01/09/2023, 7:05 PM
Can you share some of your code? That might help.
(To see what it is you’re trying to do, exactly.)
h

hundreds-yacht-71603

01/09/2023, 7:08 PM
I'm just playing around with the native provider. Nothing of use. Basically stuff like this:
lookupVpcArgs := &ec2.LookupVPCArgs{
		VpcId: *pulumi.StringRef("vpc-0b966da8f364dfd1b"),
	}

	vpc, err := ec2.LookupVPC(ctx, lookupVpcArgs, nil)
	if err != nil {
		return nil, err
	}
	log.Printf("vpc: %v", spew.Sprint(vpc))
        return nil, fmt.Errorf("I made a booboo!")
m

miniature-musician-31262

01/09/2023, 8:51 PM
Ok. Still not quite sure what you mean by “go from the VPC to the subnets”, but if you mean work with the results of the lookup, is this the kind of thing you’re looking for?
vpc, err := ec2.LookupVPC(ctx, &ec2.LookupVPCArgs{
	VpcId: *pulumi.StringRef("vpc-abc123"),
})
if err != nil {
	return err
}

<http://ctx.Log.Info|ctx.Log.Info>(*vpc.VpcId, &pulumi.LogArgs{})

for i := 0; i < len(vpc.CidrBlockAssociations); i++ {
	<http://ctx.Log.Info|ctx.Log.Info>(vpc.CidrBlockAssociations[i], &pulumi.LogArgs{})
}
(That’s using aws-native)