Hi, can I convert an Output<string> to a nor...
# general
b
Hi, can I convert an Output<string> to a normal string. I need the gke kubeconfig variable in string format.
r
If you want to create a
kubernetes provider
programmatically, you can just work with the output because a provider is also a
CustomResource
and does the await for you. The same applies for stack outputs you export. Just export the Output<string> and you will get the string. If you need programmatic access to the string value, this cannot be done synchronously, therefore just use the
apply
method like here: https://www.pulumi.com/docs/intro/concepts/programming-model/#apply
b
Thanks, although I've tried with apply already but you still end up with an Output<string>. Can I somehow programmatically save that gke kubeconfig into an actual string variable. There is a long winded explanation why I need this.
e.g. if I want to programmatically write the kubeconfig to a file using fs.writeFile(), I can't do that with an Output<string>
n
@billions-lock-80282 are you trying to get at the string prior to the plan finishing?
b
yes
n
Yeah, that's the hard part. There is no string there, because Outputs aren't fulfilled until the plan runs. It's like asking for an RDS address before the RDS instance is even created.
I was just fighting with this yesterday, in fact.
b
ah ok, the main issue is is that I have a separate cert-manager class that both eks and gke both call. But its using the
Copy code
const kubeconfig = new KubeConfig();
            kubeconfig.loadFromString(JSON.stringify(kc));
but for eks the kubeconfig is passed in as cluster.kubeconfig. But it doesn't work with the gke format unless I loadFromFile("kubeconfig")
but I wanted to create the kubeconfig file programmatically
n
IIUC that would need to become something like
Copy code
kc.apply((kcString) => { 
    kubeconfig.loadFromString(kcString)
})
b
ok, I'll give that a try, thanks
r
I would assume that in the EKS case you are also working with an unresolved kubeconfig. Is there no way of just modifying the kubeconfig in flight (using apply) and handing it in the same way? Could you show the EKS way and your KubeConfig class to better understand what you are trying to do? I don’t see why you should require the resolved string…
b
I get the following error for gke kubeconfig
Copy code
TypeError: unknown version: undefined
so it can't find the version: v1 string in the kubeconfig because its not in JSON format
I've found a way around it. EKS uses a function called generateKubeconfig which just creates the kubeconfig in JSON format. I've had to recreate that in GKE basically: