Hi, I’m new to Pulumi (not very adept in go either...
# golang
c
Hi, I’m new to Pulumi (not very adept in go either), and am trying to use a Provider output from
pulumi-eks
to create a resource in the newly created cluster. Given it’s an output type, I figured I’d need to use an
apply
(can’t pass it in directly as a pulumi ResourceOption), and though there have been many examples here in Slack and online, I am still having trouble using it. I have given an attempt, and know I am doing it wrong, but can’t seem to progress forward. if anyone has any suggestions, that would be much appreciated. Thanks in advance!
Copy code
k8sProvider := eksCluster.Provider.ApplyT(
			func(cluster kubernetes.Provider) kubernetes.Provider {
				return cluster
			}).(pulumi.ProviderResource)
b
you don’t need an apply, you just need to pass it.
what code do you have to create your cluster, and where would you like to pass it>?
c
oh, I see, we create the resources for the cluster within the ApplyT. I’ll give this a try out, thank you for the the reference to the example! should’ve checked there first 😅
f
I don’t think it’s necessary to wrap all of your resources in the ApplyT. There are some bugs that make it weird ( I think the provider exported is broken ), but you can construct your own from the kubeconfig:
Copy code
// Save a kube provider for later use
	kubeconfig := awsCluster.cluster.Kubeconfig.ApplyT(func(k interface{}) (string, error) {
		data, err := json.Marshal(k)
		if err != nil {
			return "", fmt.Errorf("kubeconfig is not a string")
		}
		return string(data), nil
	}).(pulumi.StringOutput)

	kubeProvider, err := kubernetes.NewProvider(ctx, awsCluster.Name, &kubernetes.ProviderArgs{
		Kubeconfig: kubeconfig,
	})
	if err != nil {
		return err
	}
awsCluster.cluster
is the output of an
eks.NewCluster
call
c
ah okay, i am not building out many of the kubernetes resources out through pulumi (yet), just a couple of the building blocks needed for our env. but this a good alternative to consider. the resource i’m wrapping in the apply is just an encrypted storageclass and didnt have any issues with it in the exported provider
f
Cool, yeah, that makes a lot of sense then. We’re adding a lot of things to the cluster in Pulumi, so it is much much nicer to be able to break out of the ApplyT