https://pulumi.com logo
Title
b

brash-painting-89833

04/12/2023, 6:16 PM
hello I am back trying to pulumi How can i create a vpc and get it's subnetids to use on a next step? basically i create a vpc:
vpc, err := ec2.NewVpc(ctx, name, &ec2.VpcArgs{
		CidrBlock:       pulumi.String("10.0.0.0/16"),
		InstanceTenancy: pulumi.String("default"),
		Tags: pulumi.StringMap{
			"Name": pulumi.String(name),
		},
	})
and now I want to get the subnetsids (i know they don't exit yet, and this is the problem) I basically want to use to create a eks nodeGroup, from the example: https://github.com/pulumi/examples/blob/master/aws-go-eks/main.go I have the code bellow, but it gets the vpc and subnets id using a lookup that i can't do because the vpc is yet to exit
nodeGroup, err := eks.NewNodeGroup(ctx, "node-group-2", &eks.NodeGroupArgs{
			ClusterName:   eksCluster.Name,
			NodeGroupName: pulumi.String("demo-eks-nodegroup-2"),
			NodeRoleArn:   pulumi.StringInput(nodeGroupRole.Arn),
			SubnetIds:     toPulumiStringArray(subnet.Ids),
			ScalingConfig: &eks.NodeGroupScalingConfigArgs{
				DesiredSize: <http://pulumi.Int|pulumi.Int>(2),
				MaxSize:     <http://pulumi.Int|pulumi.Int>(2),
				MinSize:     <http://pulumi.Int|pulumi.Int>(1),
			},
		})
I tried to use
LookupVpcOutput
but wasn't able to get it working, mostly because of types and etc.. Does anyone have any suggestions? if i should use the lookup or something else.. if it's the lookup, some example would be nice, i had problems getting the filter to work. Basically i want to be able to create my own vpc, and then make eks and etc use this vpc, it seems it should be a simple thing, but i guess i am not getting the right idea on inputs/outputs
s

salmon-account-74572

04/12/2023, 6:19 PM
If you use
awsx.ec2.NewVpc
then you’ll get a VPC, subnets, gateways, routes, route tables, etc. Right now you’re using
aws.ec2.NewVpc
, which creates just the VPC. For an example of how create a VPC using AWSX and then creating an EKS cluster, take a look at our Kubernetes on AWS template: https://www.pulumi.com/templates/kubernetes/aws/ The referenced template is found in our “templates” repository on GitHub: https://github.com/pulumi/templates/ (look for “kubernetes-aws-{lang}“)
b

brash-painting-89833

04/12/2023, 6:25 PM
thanks is there any recommendation on what module etc to use? i had found this awsx (https://github.com/pulumi/pulumi-awsx) but had not much stars.. like i also found this: https://github.com/pulumi/pulumi-eks/ but i am not sure which is the most supported/recommened edit: typo in url
s

salmon-account-74572

04/12/2023, 6:31 PM
Maybe it’s just me, but those URLs look the same…? 🤔 Regardless, using the module that’s referenced in the templates is the right one to use (it’s the same one you linked to). It’s currently at version 1.0.1 and is supported by Pulumi.
Same goes for AWSX, which is now at version 1.0.2 and is supported by Pulumi.
b

billowy-army-68599

04/12/2023, 6:33 PM
you can just specify the subnets as an output
nodeGroup, err := eks.NewNodeGroup(ctx, "node-group-2", &eks.NodeGroupArgs{
			ClusterName:   eksCluster.Name,
			NodeGroupName: pulumi.String("demo-eks-nodegroup-2"),
			NodeRoleArn:   pulumi.StringInput(nodeGroupRole.Arn),
			SubnetIds:    vpc.privateSubnetIds,
			ScalingConfig: &eks.NodeGroupScalingConfigArgs{
				DesiredSize: <http://pulumi.Int|pulumi.Int>(2),
				MaxSize:     <http://pulumi.Int|pulumi.Int>(2),
				MinSize:     <http://pulumi.Int|pulumi.Int>(1),
			},
		})
s

salmon-account-74572

04/12/2023, 6:34 PM
Exactly. In @billowy-army-68599’s example code above,
vpc
would be the name of the VPC created using AWSX, so
vpc.privateSubnetIds
references the private subnets created in the VPC by Crosswalk for AWS (AWSX).
Does that help?
b

brash-painting-89833

04/13/2023, 2:04 AM
@salmon-account-74572 i fixed the url thanks for all the info @billowy-army-68599 i will try with the module now But the questions regarding modules was like, we have this both for eks: https://github.com/pulumi/pulumi-eks and https://github.com/pulumi/pulumi-aws/tree/master/sdk/go/aws/eks either way, thanks for the info