https://pulumi.com logo
#kubernetes
Title
# kubernetes
b

bright-needle-80161

03/14/2022, 5:29 PM
Hello Community! I am trying to use the imported
kubeconfig
from another project to create a new provider on the new projct based on that file using the
ApplyT
golang method to convert the
AnyOutput
data type to a
pulumi.ProviderResource
type. Can someone explain to me how can I do it? A snippet of golang code is below.
Copy code
// Create stack reference to prvious projct named  "ccmx/eks/dev"
stack_output, err := pulumi.NewStackReference(ctx, "ccmx/eks/dev", nil)
		if err != nil {
			log.Fatalf("error creating stack reference: %v", err)
		}
// Import kubeconfig from the stack "ccmx/eks/dev"
kubeconfig := stack_output.GetOutput(pulumi.String("kubeconfig"))

// Create Kuberntes provider
K8sProvider, err := kubernetes.NewProvider(ctx, "eks-provider", &kubernetes.ProviderArgs{
			//Kubeconfig: pulumi.String(kubeconfig),
			Kubeconfig: kubeconfig.ApplyT(func(s string) string { return s }).(pulumi.Provider),
		})

		if err != nil {
			log.Fatalf("error creating K8s provider: %v", err)
		}
I am getting the following error when executing
pulumi up
:
Copy code
Diagnostics:
  pulumi:pulumi:Stack (kubernetes-ccmx/kubernetes/dev):
    error: an unhandled error occurred: program exited with non-zero exit code: 2

    # kubernetes
    ./main.go:26:69: impossible type assertion:
    	func(pulumi.ProviderResource) pulumi.ResourceOrInvokeOption does not implement pulumi.Output (missing ApplyT method)
    ./main.go:26:71: pulumi.Provider is not a type
If I removed the
ApplyT
method, this is what the provider creation looks like
Copy code
K8sProvider, err := kubernetes.NewProvider(ctx, "eks-provider", &kubernetes.ProviderArgs{
			//Kubeconfig: pulumi.String(kubeconfig),
			Kubeconfig: kubeconfig,
		})
The execution error message changed to the below
Copy code
Diagnostics:
  pulumi:pulumi:Stack (kubernetes-ccmx/kubernetes/dev):
    # kubernetes
    ./main.go:26:4: cannot use kubeconfig (type pulumi.AnyOutput) as type pulumi.StringPtrInput in field value:
    	pulumi.AnyOutput does not implement pulumi.StringPtrInput (missing ToStringPtrOutput method)

    error: an unhandled error occurred: program exited with non-zero exit code: 2
I got the explanation I was looking for from this previous discussion https://pulumi-community.slack.com/archives/C84L4E3N1/p1643663176410659. However, I am now getting another error from the
pulumi up
execution.
Copy code
error: an unhandled error occurred: program exited with non-zero exit code: 1

    error: program failed: waiting for RPCs: Invoke(pulumi:pulumi:getResource, ...): error: rpc error: code = Unknown desc = invocation of pulumi:pulumi:getResource returned an error: unknown resource urn:pulumi:ccmx/eks/dev::eks::pulumi:providers:kubernetes::eksProvider
    exit status 1
Would anyone know exactly what this error message is trying to say?
7 Views