Hey all. I need that I've been stack in for days n...
# general
f
Hey all. I need that I've been stack in for days now. My scenario is, I am creating the vpc first, and then I am supposed to use the vpc id while creating eks cluster. They must be created separately. I have one function that runs Upsert
Copy code
func PulumiOps(program func(ctx *pulumi.Context) error, project_name, stack_name, region string, vpcProgram pulumi.RunFunc, ctx context.Context) (auto.OutputMap, error) {
	
	stack, err := auto.UpsertStackInlineSource(ctx, stack_name, project_name, vpcProgram)

	if err != nil {
		logrus.Error("Could not create stack: ", err)
		return auto.OutputMap{}, err
	}

	err = stack.SetConfig(ctx, "aws:region", auto.ConfigValue{Value: region})
	if err != nil {
		logrus.Error("Could not set config: ", err)
		return auto.OutputMap{}, err
	}


// Create a new VPC with a public and private subnet.
  func A(ctx *pulumi.Context) err
	vpc, err := awsx.NewVpc(ctx, project_name, &awsx.VpcArgs{
		CidrBlock: pulumi.StringRef("10.0.0.0/16"),
		Tags: pulumi.StringMap{
			"Name": pulumi.String(project_name),
		},
		NumberOfAvailabilityZones: pulumi.IntRef(4),
		SubnetSpecs: []awsx.SubnetSpecArgs{
			{
        <other args>
        ctx.Export("vpcId", vpc.VpcId)
Copy code
func B(ctx *pulumi.Context) err
       
	// Create an EKS cluster.
	cluster, err := eks.NewCluster(ctx, project_name, &eks.ClusterArgs{
		InstanceType: pulumi.String(eksNodeInstanceType),
		VpcId: 	  pulumi.Sprintf( vpcid),
		PublicSubnetIds:  vpc.PublicSubnetIds ,
		PrivateSubnetIds: vpc.PrivateSubnetIds ,
		MinSize: <http://pulumi.Int|pulumi.Int>(minClusterSize),
		MaxSize: <http://pulumi.Int|pulumi.Int>(maxClusterSize),
		DesiredCapacity: <http://pulumi.Int|pulumi.Int>(desiredClusterSize),
		NodeAssociatePublicIpAddress: pulumi.BoolRef(false),
    
        <other args>
        ctx.Export("kubeconfig", cluster.kubeconfig)

So whenever I create VPC with 
PulumiOps(.... B...) //snippet ---> This create the vpc correctly and I get the vpc id

Then the next time I want to create eks or any other resource using 
Pulumi(...A...) ----->>> This subsequent resource deletes everything that was created by vpc.

The requirement is to call func A first. Wait for to finish then somewhere else, func B is called and provided with vpcid from func A.

func A works perfect, func B deletes all the resources
That works perfectly, I get vpc id and store it somewhere Why is this happening and how can I fix it. Thank you very much.
m
I think you're already on the right track here: https://pulumi-community.slack.com/archives/CRFURDVQB/p1723585294350679