https://pulumi.com logo
#general
Title
# general
s

square-night-79134

06/22/2023, 4:02 PM
When I saw the pulumi AI and documentation there is no such information related to getClusterArgs and the link or method is pointing to LookUpCluster, Any hint what’s happening here?
s

salmon-account-74572

06/22/2023, 4:09 PM
One oddity of the Go SDK is that the
Get*
functions are named
Lookup*
instead. So, rather than using
container.GetCluster
you’d use
container.LookupCluster
. Instead of using
&container.GetClusterArgs
you’d use
&container.LookupClusterArgs
. This page has an example (be sure to click the Go language selector): https://www.pulumi.com/registry/packages/gcp/api-docs/container/getcluster/
s

square-night-79134

06/22/2023, 4:16 PM
Thanks I was confused with pulumi AI and the documentation, How ever there is another issue I am using code but it’s not in the documentation (generated by AI) Idea is to generate a new cluster using the existing configuration
Copy code
newCluster, err := container.NewCluster(ctx, "new-cluster", &container.ClusterArgs{
			AddonsConfig:              existingCluster.AddonsConfig,
			ClusterAutoscaling:        existingCluster.ClusterAutoscaling,
			DefaultSnatStatus:         existingCluster.DefaultSnatStatus,
			EnableKubernetesAlpha:     existingCluster.EnableKubernetesAlpha,
			EnableTpu:                 existingCluster.EnableTpu,
			IpAllocationPolicy:        existingCluster.IpAllocationPolicy,
			Location:                  pulumi.String("your-new-cluster-location"),
			LoggingService:            existingCluster.LoggingService,
			MaintenancePolicy:         existingCluster.MaintenancePolicy,
			NetworkPolicy:             existingCluster.NetworkPolicy,
			PodSecurityPolicyConfig:   existingCluster.PodSecurityPolicyConfig,
			PrivateClusterConfig:      existingCluster.PrivateClusterConfig,
			Project:                   newProjectID,
			ResourceLabels:            existingCluster.ResourceLabels,
			ResourceUsageExportConfig: existingCluster.ResourceUsageExportConfig,
		})
s

salmon-account-74572

06/22/2023, 4:21 PM
I’ve never tried something like that, and honestly don’t know if it would work. If you aren’t sure what settings to use, I would take a look at the
kubernetes-gcp-go
template (run
pulumi new kubernetes-gcp-go
and review the program created from it). Then compare that against what is already there.
s

square-night-79134

06/22/2023, 4:25 PM
sure thing! Idea is to collect the existing gcp cluster info (Auto pilot) including NAT, VPC (private and public) and create a new cluster using the same replica apart from the fixed IP address in a different project. Is that doable. How ever this my current code
Copy code
package main

import (
	"<http://github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/container|github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/container>"
	"<http://github.com/pulumi/pulumi/sdk/v3/go/pulumi|github.com/pulumi/pulumi/sdk/v3/go/pulumi>"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Get existing GKE cluster
		existingCluster, err := container.LookupCluster(ctx, &container.LookupClusterArgs{
			Location: pulumi.StringRef("your-existing-cluster-location"),
			Name:     "your-existing-cluster-name",
			Project:  pulumi.StringRef("your-existing-project-id"),
		})
		if err != nil {
			return err
		}

		// Change "your-new-project-id" to the new project ID where you want to create the cluster
		newProjectID := pulumi.String("your-new-project-id")

		// Create a new GKE cluster with the same settings in a different project
		newCluster, err := container.NewCluster(ctx, "new-cluster", &container.ClusterArgs{
			AddonsConfig:              existingCluster.AddonsConfig,
			ClusterAutoscaling:        existingCluster.ClusterAutoscaling,
			DefaultSnatStatus:         existingCluster.DefaultSnatStatus,
			EnableKubernetesAlpha:     existingCluster.EnableKubernetesAlpha,
			EnableTpu:                 existingCluster.EnableTpu,
			IpAllocationPolicy:        existingCluster.IpAllocationPolicy,
			Location:                  pulumi.String("your-new-cluster-location"),
			LoggingService:            existingCluster.LoggingService,
			MaintenancePolicy:         existingCluster.MaintenancePolicy,
			NetworkPolicy:             existingCluster.NetworkPolicy,
			PodSecurityPolicyConfig:   existingCluster.PodSecurityPolicyConfig,
			PrivateClusterConfig:      existingCluster.PrivateClusterConfig,
			Project:                   newProjectID,
			ResourceLabels:            existingCluster.ResourceLabels,
			ResourceUsageExportConfig: existingCluster.ResourceUsageExportConfig,
		})
		if err != nil {
			return err
		}

		ctx.Export("newClusterName", newCluster.Name)
		ctx.Export("ClusterEndpoint", newCluster.Endpoint)
		return nil
	})
}
As per suggested by pulumi AI it’s doable but the AI is giving the old code and not relevant
s

salmon-account-74572

06/22/2023, 4:34 PM
I’m checking now to see if the idea of using
LookupCluster
to feed information into
NewCluster
is supported/feasible. My IDE definitely doesn’t like your code; it’s throwing all kinds of type errors.
s

square-night-79134

06/22/2023, 4:37 PM
yes, same here. Do let me know if you find anything
In the library I am seeing these two functions
Copy code
// NewCluster registers a new resource with the given unique name, arguments, and options.
func NewCluster(ctx *pulumi.Context,
	name string, args *ClusterArgs, opts ...pulumi.ResourceOption) (*Cluster, error) {
	if args == nil {
		args = &ClusterArgs{}
	}

	var resource Cluster
	err := ctx.RegisterResource("gcp:container/cluster:Cluster", name, args, &resource, opts...)
	if err != nil {
		return nil, err
	}
	return &resource, nil
}

// GetCluster gets an existing Cluster resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetCluster(ctx *pulumi.Context,
	name string, id pulumi.IDInput, state *ClusterState, opts ...pulumi.ResourceOption) (*Cluster, error) {
	var resource Cluster
	err := ctx.ReadResource("gcp:container/cluster:Cluster", name, id, state, &resource, opts...)
	if err != nil {
		return nil, err
	}
	return &resource, nil
}
@salmon-account-74572 Any luck?
s

salmon-account-74572

06/22/2023, 5:52 PM
I haven’t gotten any responses from the engineering team yet. My advice to you, if this is time-sensitive, would be to use the
kubernetes-gcp-go
template and iterate on that to create a matching resource.
s

square-night-79134

06/23/2023, 7:33 AM
Ah! I will wait for the response because it's seems very confusing to me. I even tried pulumi import BTW
s

salmon-account-74572

06/23/2023, 2:22 PM
pulumi import
should generate code for you, and you can then duplicate that code to create another resource. But as someone else pointed out in another thread, with an Autopilot cluster a lot of the settings won’t come in (because Autopilot handles all that).